異常:Transaction not successfully started
阿新 • • 發佈:2018-11-01
exce getc get 詳情 異常 except ransac nsa ber 異常:org.hibernate.TransactionException: Transaction not successfully started
錯誤代碼: service層 Session session = HibernateUtils.getCurrentSession(); //....數據庫操作語句(調用dao層) Transaction tx = session.beginTransaction(); tx.commit(); dao層 Session session = HibernateUtils.getCurrentSession(); //....數據庫操作語句 Transaction tx = session.beginTransaction(); tx.commit();
異常詳情:
![](http://i2.51cto.com/images/blog/201811/01/b3a475128fe693546c7d8d34cefac421.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)
一翻檢查分析後發現原因:
原來是我在同一個線程中創建了兩個事務對象,
這違背了事務ACID特性中的 Isolation隔離性。
解決方案:
只要把dao層重復的事務代碼去掉即可,如下: Transaction tx = session.beginTransaction(); tx.commit();
異常:Transaction not successfully started