spring4 hibernate5配置 getHibernateFlushMode is not valid without active transaction
来源:互联网 发布:监控系统怎么连接网络 编辑:程序博客网 时间:2024/05/17 20:22
最近在做spring4和hibernate5的整合
不小心出了这个错误,是因为我不小心配置了:
hibernate.current_session_context_class = thread 导致的,这使我好好学习了一把
如果是单独使用hibernate,那么自然设置最好,因为这会使得hibernate能够从本地线程中getCurrentSession得到同一个session会话
但是spring和hibernate集成的时候,就不能这样设置了
在Spring @Transactional声明式事务管理,”currentSession”的定义为: 当前被 Spring事务管理器 管理的Session
事务管理已经交给了spring去控制,那么current_session_context当前会话上下文就应该交给spring的这个类:SpringSessionContext(当然这个也是spring 的默认配置)
如果在集成spring和hibernate的时候设置为thread,会导致hibernate使用org.hibernate.context.internal.ThreadLocalSessionContext
结果就是,调用hibernate的session做增删改操作的时候,spring找不到当前应用上下文中有效的transaction
另外,再附上某位大神的深度解释,深入源码,值得仔细看看,了解hibernate对session context的控制和spring对此的实现机制!
http://blog.csdn.net/naruto_Mr/article/details/48085191
一定静下心来看。。。。。。
- spring4 hibernate5配置 getHibernateFlushMode is not valid without active transaction
- getHibernateFlushMode is not valid without active transaction;
- 使用spring4+springMVC+hibernate5 时报错:createQuery is not valid without active transaction;
- createQuery is not valid without active transaction
- getFlushMode is not valid without active transaction
- createQuery is not valid without active transaction
- createQuery is not valid without active transaction
- getFlushMode is not valid without active transaction
- hibernate中: is not valid without active transaction
- spring,hiberante之*** is not valid without active transaction
- spring,hiberante之*** is not valid without active transaction
- org.hibernate.HibernateException: createSQLQuery is not valid without active transaction
- createQuery is not valid without active transaction异常
- hibernate错误:load is not valid without active transaction
- org.hibernate.HibernateException: delete is not valid without active transaction
- createSQLQuery is not valid without active transaction的解决办法
- Hibernate SessionFactory getCurrentSession is not valid without active transaction
- org.hibernate.HibernateException: save is not valid without active transaction
- Spring boot 数据源未配置异常
- 大数据Hadoop学习六
- 关于登陆的配置问题总结
- 排序——插入排序
- SolrCloud基础认识
- spring4 hibernate5配置 getHibernateFlushMode is not valid without active transaction
- Zookeeper实例Curator API-TestingServer
- spark程序运行缓慢
- servlet生命周期
- 【JSON学习】--简介
- Zookeeper实例Curator API-TestingCluster
- windows运行 HiveContext 报错
- spark-SQL的DataFrame和DataSet
- Spark集成 hadoop,hbase 的 maven冲突