Syed Shah created DELTASPIKE-1407:
-------------------------------------
Summary: DeltaSpike Data @Modifying Updates Database, but Selects
Retain Old Value
Key: DELTASPIKE-1407
URL: https://issues.apache.org/jira/browse/DELTASPIKE-1407
Project: DeltaSpike
Issue Type: Bug
Security Level: public (Regular issues)
Components: Data-Module
Affects Versions: 1.9.3
Reporter: Syed Shah
I have the following code:
```java
@Repository(forEntity = GuildData.class)
public interface GuildRepository extends EntityRepository<GuildData, Long> {
/**
* @param id The ID of the guild.
* @param prefix What to set he guild's prefix to.
* @return The number of rows that changed, this should always be 1.
*/
@Modifying
@Query("UPDATE GuildData AS g SET g.prefix = ?1 WHERE g.id = ?2")
int updatePrefix(final String prefix, final long id);
}
```
However, when I do the following, the database updates successfully, however
when the application next does a query for the entity it still returns the old
value until the application has restarted?
```java
private void setPrefix(long guildId, String prefix) {
int result = guildRepo.updatePrefix(prefix, guildId);
logger.debug("Prefix command performed and updated {} prefix in the
database.", result);
}
```
This however, gets the desired behavior:
```java
private void setPrefix(long guildId, String prefix) {
GuildData data = guildRepo.findBy(guildId);
if (data == null)
data = new GuildData(guildId);
data.setPrefix(prefix);
guildRepo.save(data);
}
```
--
This message was sent by Atlassian Jira
(v8.3.4#803005)