[英]using spring transactionManager with Hibernate after transaction committed only one repository of two is actually being committed
我有一個@Transactional
方法,它改變了兩個不同的、不相關的存儲庫實體的狀態。
像這樣:
@Transactional
public void foo() {
A a = repoA.findById(1);
a.setState(s1);
B b = repoB.findById(1);
b.setState(s2);
// (and I also do repoA.save(a); and repoB.save(b); although it is redundant)
}
我還有一個事務方法bar
,它調用foo
並發布一個由TransactionalEventListener
捕獲的事件,如下所示:
@Transactional
public void bar() {
foo();
applicationEventPublisher.publishEvent(new AppEvent(123));
}
和
@Component
public class MyApplicationEventListener {
@TransactionalEventListener
public void handleAfterCommit(AppEvent appEvent){
//do something;
}
}
現在的問題是,在調用handleAfterCommit
方法的 80% 的時間里,只有(A a )
被提交,但(B b)
正在丟失其更改。
我需要幫助來了解這里發生了什么,我嘗試調試和探索TransactionAspectSupport.currentTransactionStatus()
但沒有找到任何見解。
謝謝,
愛隆
我發現了這個問題,我們正在使用自定義 AttributeConverter 並且我們沒有為相關的 javav 對象實現 Equals,這導致 select 上的每個臟檢查都失敗並進行完整更新(覆蓋同時已更改的值)
謝謝
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.