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并没有关闭
/*2. getCurrentSession的使用可以参见hibernate\hibernate-3.2\doc\tutorial\src项目
3. 使用SessionFactory.getCurrentSession()需要在hibernate.cfg.xml中如下配置:
* 如果采用jdbc独立引用程序配置如下:
<property name="hibernate.current_session_context_class">thread</property>
* 如果采用了JTA事务配置如下
<property name="hibernate.current_session_context_class">jta</property>*/
开始用的:
Session session = this.getHibernateTemplate().getSessionFactory().getCurrentSession();
Transaction tran=session.beginTransaction();
好多文章里都说只需在Spring配置<bean id="sessionFactory"...---><property name="hibernateProperties"> 中加入 <prop key="hibernate.current_session_context_class">thread</prop>就可以解决,试了没用.
修改后的:
Session session = this.getHibernateTemplate().getSessionFactory().openSession();
Transaction tran=session.beginTransaction();
......
finally
{
session.close();
}
问题解决
相关推荐
Could not roll back Hibernate transaction.doc
之前一直找原因,最后知道了解决方法,具体请下载源码查看。特别是用到throw的事务中
主要介绍了Codeigniter框架的更新事务(transaction)BUG及解决方法,具体BUG和解决办法在文中有详细描述,需要的朋友可以参考下
在使用maven开发web项目极大地方便了jar包的依赖,在测试时也可以集成Servlet容器,从启动速度和量级上看,Jetty无疑是不二选择,然而从8.x开始,如果你的web项目中不包含数据库访问(或者说没有事务管理器)的话,...
Principles of transaction processing Copyright © 2009 by Elsevier Inc. All rights reserved
javax.transaction.jar javax.transaction.jar
赠送jar包:javax.transaction-api-1.2.jar; 赠送原API文档:javax.transaction-api-1.2-javadoc.jar; 赠送源代码:javax.transaction-api-1.2-sources.jar; 赠送Maven依赖信息文件:javax.transaction-api-1.2....
赠送jar包:javax.transaction-api-1.2.jar; 赠送原API文档:javax.transaction-api-1.2-javadoc.jar; 赠送源代码:javax.transaction-api-1.2-sources.jar; 赠送Maven依赖信息文件:javax.transaction-api-1.2....
TransactionDemo
.NET Framework使得这一切变得很简单,事实上我们不用在组件服务中作任何事,这一切都是自动完成的。对WebService来说,.NET Framework用Enterprise Services(COM+的替代者)来管理事务,而无需创建一个COM+包。...
requires 'org.eclipse.emf 2.6.0' but it could not be found),解决方法:将“离线解决方案”文件夹中的org.eclipse.emf 2.6.0的jar,拷贝到自己的eclipse的plugin文件夹下面,重启eclipse再次安装activiti插件就...
transaction_processing_concepts_and_techniques
Principles of Transaction Processing for the Systems Professional explains that these and many other computerized tasks require the use of transaction processing (TP).
Ogc wfs Transaction 修改Feature 完整例子 代码
Fault-tolerant consensus algorithms also reach agreement, but do not block whenever any majority of the processes are working. The Paxos Commit algorithm runs a Paxos consensus algorithm on the ...
SSH(struts+spring+hibernate)的jar包 SSH 通常指的是 Struts2 做前端控制器,Spring 管理各层的组件,Hibernate 负责持久化层。 一个请求在Struts2框架中的处理大概分为以下几个步骤: 1、客户端初始化一个指向...
SSH的整合问题集中处理 <!-- 事务配置 --> <!-- JTA环境的事务配置 <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager or ...
介绍Hibernate+Transaction+myeclipse6+事例的应用参考工程源码.
TCC-Transaction分布式事务DEMO,基于Mysql数据库的事务,包括分布式提交和回滚,例子完成,可以正常跑,基于Maven构建的项目