转:Could not commit Hibernate 问题,spring 事物 提交前session关闭
2016-11-23 20:41
441 查看
org.springframework.transaction.TransactionSystemException: Could not commit Hibernate transaction; nested exception is org.hibernate.TransactionException: Transaction not successfully started
最近在写操作CLOB的过程中总是报这个异常,数据去插入进去了.
先看看SessionFactory.getCurrentSession与openSession的区别
1. 如果使用的是getCurrentSession来创建session的话,在commit后,session就自动被关闭了,
也就是不用再session.close()了。但是如果使用的是openSession方法创建的session的话,
那么必须显示的关闭session,也就是调用session.close()方法。这样commit后,session并没有关闭
开始用的:
Session session = this.getHibernateTemplate().getSessionFactory().getCurrentSession();
Transaction tran=session.beginTransaction();
好多文章里都说只需在Spring配置 中加入 thread就可以解决,试了没用.
修改后的:
Session session = this.getHibernateTemplate().getSessionFactory().openSession();
Transaction tran=session.beginTransaction();
......
finally
{
session.close();
}
问题解决
最近在写操作CLOB的过程中总是报这个异常,数据去插入进去了.
先看看SessionFactory.getCurrentSession与openSession的区别
1. 如果使用的是getCurrentSession来创建session的话,在commit后,session就自动被关闭了,
也就是不用再session.close()了。但是如果使用的是openSession方法创建的session的话,
那么必须显示的关闭session,也就是调用session.close()方法。这样commit后,session并没有关闭
开始用的:
Session session = this.getHibernateTemplate().getSessionFactory().getCurrentSession();
Transaction tran=session.beginTransaction();
好多文章里都说只需在Spring配置 中加入 thread就可以解决,试了没用.
修改后的:
Session session = this.getHibernateTemplate().getSessionFactory().openSession();
Transaction tran=session.beginTransaction();
......
finally
{
session.close();
}
问题解决
相关文章推荐
- 转:Could not commit Hibernate 问题,spring 事物 提交前session关闭问题
- 转:Could not commit Hibernate 问题,spring 事物 提交前session关闭问题
- Could not commit Hibernate 异常问题,spring 事物 提交前session关闭问题
- Spring-hibernate开发时遇到 Could not obtain transaction-synchronized Session for current thread的问题解决
- 解决Could not open Hibernate Session for transaction问题
- Could not open Hibernate Session for transaction; nested exception is.....远程服务器部署后出现这个问题分析
- 解决Could not open Hibernate Session for transaction问题
- 出现org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed问题以及解决办法
- org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session
- 最近用STS搭建hibernate&spring,遇到Could not locate SessionFactory in JNDI.找到这个文章很快解决了
- Spring JPA Hibernate problem: LazyInitializationException: could not initialize proxy no session
- 解决Hiberante延迟加载问题——could not initialize proxy - no Session & 简介Hibernate的持久化
- Spring+Hibernate出错: could not initialize proxy - the owning Session was closed
- Spring对Hibernate的session生效期(事物提交管理)介绍
- org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session f
- org.hibernate.LazyInitializationException: could not initialize proxy - no Session懒加载问题
- hibernate--could not initialize proxy - no Session--懒加载问题
- 解决org.hibernate.LazyInitializationException: could not initialize proxy - no Session问题
- 解决org.hibernate.LazyInitializationException: could not initialize proxy - no Session懒载入问题
- 解决org.hibernate.LazyInitializationException: could not initialize proxy - no Session懒加载问题