当前位置: 代码迷 >> J2EE >> Hibernate报错误“nested transactions not supported“,这如何解决啊
  详细解决方案

Hibernate报错误“nested transactions not supported“,这如何解决啊

热度:741   发布时间:2016-04-19 22:17:11.0
Hibernate报异常“nested transactions not supported“,这怎么解决啊?

public boolean saveFilmInfo(FilmInfo info) {
boolean flag = false;
Transaction tx = null;
try {
tx = getSession().beginTransaction();
getSession().save(info);
tx.commit();
flag = true;
} catch (Exception e) {
// TODO: handle exception
tx.rollback();
e.printStackTrace();
}
return flag;
}

运行到tx = getSession().beginTransaction();这里时就报异常为:org.hibernate.TransactionException: nested transactions not supported
怎么回事啊,搞不懂了。其它就没问题
------解决方案--------------------
事务嵌套了?
------解决方案--------------------

 tx = getSession().beginTransaction();

改成

 tx = getSession().beginTransaction().begin();
------解决方案--------------------
引用:
tx = getSession().beginTransaction();

改成

 tx = getSession().beginTransaction().begin();


我傻X了、

是这样的

 tx = getSession().beginTransaction();//获取事务

 tx.begin(); //开启事务
  相关解决方案