我目前在無狀態會話中執行事務有問題。@Transactional裏面的無狀態會話
在服務層上,我定義了使用@Transactional
註釋(因爲方法需要在一個事務中)所需的事務。 在該方法內部,我創建了新實體Car
。 不過我也有襯墊的方法無狀態會話(其履行完成)內定製transtaction這樣
StatelessSession session = getSessionFactory().openStatelessSession();
Transaction transaction = session.beginTransaction()
// create and setup CarRequirements entity
transaction.commit;
問題創造的是,實體CarRequirements
有外鍵實體Car
。因此,當我嘗試提交下層事務時會發生異常,因爲顯然Car
實體尚未提交到數據庫。
有沒有辦法推遲下層事務的提交或強制提交Car
實體?
這些實體如何映射? – davidxxx
@davidxxx CarRequirement有引用汽車主鍵的外鍵 – toucheqt