在我們的java項目中,我們使用了帶有hibernate和spring的ORM。 我在刪除持久對象時遇到了問題。例如,這樣的方法通過IDS得到實體,然後將其刪除:Spring transaction propagation_required issue
@Transactional
public void remove(List<Long> ids) {
SearchTemplate template = new SearchTemplate();
template.addParameter("milestoneId",ids);
List <InvoiceQueue> items = this.findByCriteria(template);
...
this.delete(items);
}
方法執行好,沒有任何異常,但實際上並沒有刪除數據庫中的項目。
將以下注釋添加到方法定義@Transactional(propagation = Propagation.REQUIRES_NEW)
可解決問題。
任何人都可以解釋爲什麼它不適用於默認傳播類型PROPAGATION_REQUIRED。
在此先感謝。
環境的詳細信息:
hibernate.version 3.5.5決賽,spring.version 3.0.5.RELEASE
周圍的交易可能有問題。如果您使用PROPAGATION_REQUIRED,則此方法使用當前事務。如果在運行此方法後當前事務中存在異常,則可能會回滾這些更改。 –