Search code examples
javaquarkusnarayanaquarkus-hibernate-orm

Quarkus-Hibernate-ORM EntityManager.merge() is not updating database


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.


Solution

  • 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) {...}
    }