簡體   English   中英

Quarkus-Hibernate-ORM EntityManager.merge() 沒有更新數據庫

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

我有一個帶有實體的 quarkus 應用程序和一個 DAO Class。

現在我嘗試通過調用 EntityManager 的 merge() function 來更新實體:

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

EntityManager 被注入:

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

DAO 的 class 是@Singleton

當我調用update()時,我沒有收到異常,日志中也沒有任何信息,但是數據庫沒有更新。 當我在 entityManager 上執行persist()remove()時,它按預期工作。

我進一步處理交易:

@Inject
private EntityDAO entityDao;

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

有什么想法可能是這個問題的問題嗎?

編輯:記錄...

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

所以我證明,如果 hibernate session 臟了,

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

而且合並后session也不臟。

解決方案是錯誤的@Entity class

@Entity
public class ValueObject {
  private String value;

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

必須改為:

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

  public getValue() {...}
  
  public setValue(String value) {...}
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM