0

I have a quarkus application with an Entity, and an DAO Class.

Now I try to update the Entity by calling the merge() function of the EntityManager:

public void update(final T valueObject) {
  getEntityManager().merge(valueObject);
}

The EntityManager is injected:

@Inject
@PersistenceUnit("MY_DB")
protected EntityManager _entityManager;

and the class of the DAO is a @Singleton

When I call update() I get no Exception and there is also no information in the logs, but the database is just not updated. When I perform a persist() or remove() on the entityManager, that works as expected.

I furher work with transactions:

@Inject
private EntityDAO entityDao;

QuarkusTransaction.begin();
entity.setValue("my value");
entityDao.update(entity);
QuarkusTransaction.commit();

Any ideas what could be the problem on this issue?

Edit: Log...

DEBUG [org.hib.eve.int.AbstractFlushingEventListener] (executor-thread-0) Processing flush-time cascades
DEBUG [org.hib.eve.int.AbstractFlushingEventListener] (executor-thread-0) Dirty checking collections
DEBUG [org.hib.eve.int.AbstractFlushingEventListener] (executor-thread-0) Flushed: 0 insertions, 0 updates, 0 deletions to 1 objects
DEBUG [org.hib.eve.int.AbstractFlushingEventListener] (executor-thread-0) Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
DEBUG [org.hib.int.uti.EntityPrinter] (executor-thread-0) Listing entities:
DEBUG [org.hib.int.uti.EntityPrinter] (executor-thread-0) at....{THE UPDATED DATA}
DEBUG [at...LoggingInterceptor] (executor-thread-0) at....update() finished

So I proofed, if the hibernate session is dirty,

boolean before = _session.isDirty();
_session.merge(valueObject);
boolean after = _session.isDirty();

but also after merging the session is not dirty.

Jakob Graf
  • 376
  • 1
  • 3
  • 14
  • Does this answer your question? [JPA EntityManager: Why use persist() over merge()?](https://stackoverflow.com/questions/1069992/jpa-entitymanager-why-use-persist-over-merge) – Luca Basso Ricci Sep 27 '22 at 05:17
  • @LucaBassoRicci unluckily not, since what I understand merging the changes should persist the object to the related database entry. – Jakob Graf Sep 27 '22 at 06:07
  • Try enabling SQL logging to see what happens. – ewramner Sep 27 '22 at 11:24
  • Somehow when flushing, there is no update on this object, but the entity contains the changed data. See updated Log output. – Jakob Graf Sep 27 '22 at 11:41

1 Answers1

1

The solution was a wrong @Entity class

@Entity
public class ValueObject {
  private String value;

  @Column(name = "VALUE")
  public getValue() {...}
  
  public setValue(String value) {...}
}

had to be changed to:

@Entity
public class ValueObject {
  @Column(name = "VALUE")
  private String value;

  public getValue() {...}
  
  public setValue(String value) {...}
}
Jakob Graf
  • 376
  • 1
  • 3
  • 14