ssh框架遇到的异常

ssh框架遇到的错误
[size=large]今天学习ssh视频时,遇到如下错误:
org.springframework.transaction.TransactionSystemException: Could not commit Hibernate transaction; nested exception is org.hibernate.TransactionException: Transaction not successfully started
Caused by: org.hibernate.TransactionException: Transaction not successfully started

解决办法及分析:
解决办法:因为我用的是openSession方法,所以要把方法中的session.Close()去掉

分析:如果使用的是getCurrentSession来创建session的话,在commit后,session就自动被关闭了,也就是不用再session.close()。
但是如果使用的是openSession方法创建的session的话, 那么必须显示的关闭session,也就是调用session.close()方法。这样commit后,session并没有关闭
[size=medium]