异常:Transaction not successfully started
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了异常:Transaction not successfully started相关的知识,希望对你有一定的参考价值。
异常: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的主要内容,如果未能解决你的问题,请参考以下文章
Transaction not successfully started&&Could not commit Hibernate transaction;
ssh框架 Could not commit Hibernate transaction问题
save is not valid without active transaction
win7 sp1 Error_transaction_not_active
Could not open Hibernate Session for transaction
事务配置不对导致:?Could not obtain transaction-synchronized Session for current thread