zf_1024
2017-10-02 13:35hibernate中nested transactions not supported问题
下边这个方法是struts 中action类中的某个方法,当访问他时:
public void fortest(){
Session session = HUtil.getSession();
session.beginTransaction();
// session.flush();
session.getTransaction().commit();
session.beginTransaction();
//session.flush();
session.getTransaction().commit();
/* service.selectRoomCount(room);*/
}
会报告错误:session被关闭了,只好加上session.flush()方法。其中getSession()是获取ThreadLocal的session。
然后就会报告错误nested transactions not supported--不支持嵌套的事物。
原理不清楚,但是解决方法很简单:重新开启一个session,即调用sessionfactory.openSession()方法,
然后在事物提交后关闭session即可。
有没有能解析下原理的大神?
- 点赞
- 回答
- 收藏
- 复制链接分享
0条回答
为你推荐
- Hibernate多对多关联表问题
- 企业应用
- hibernate
- 0个回答
- hibernate的问题
- hibernate
- 0个回答
- class not found org.hibernate.dialect.SQLServerDialect
- hibernate
- 0个回答
- Hibernate查询数据时出现的问题
- hibernate
- 0个回答
- ireport 中 Spring loaded Hibernate connection 连接问题
- 企业应用
- 0个回答
换一换