异常:Transaction not successfully started struts2

异常: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();|
异常详情:
异常:Transaction not successfully started struts2一翻检查分析后发现原因:
原来是我在同一个线程中创建了两个事务对象,
这违背了事务ACID特性中的 Isolation隔离性

解决方案:
只要把dao层重复的事务代码去掉即可,如下:
Transaction tx = session.beginTransaction();
tx.commit();

上一篇:Wamp win10 1077error


下一篇:hibernater的 Transaction not successfully started 异常错误解决