org.hibernate.TransactionException: nested transactions not supported错误的解决方法

用ssh架构进行开发的时候。配置hibernate如果出现org.hibernate.TransactionException: nested transactions not supported这个异常,那是因为事务没有提交 。一般是实现DAO接口的那个java文件。Transaction的对象没有提交事务 也就是commit()这个方法,例如以下代码:

public void addPerson(Person person) 

{

Session session = HibernateUtil.getSession();

Transaction tx = session.beginTransaction();

try 

{

session.persist(person);

tx.commit();             //必须加上这句

} catch (Exception e) 

{

if (null != tx)

tx.rollback();

e.printStackTrace();

}

}

猜你喜欢

转载自blog.csdn.net/thomassamul/article/details/81331264