Spring和Hibernate整合事务配置之current_session_context_class
2018-01-11 10:25
513 查看
hibernate.current_session_context_class设置
原来配置事务模式:
<prop key="hibernate.current_session_context_class">thread</prop>
会出现不存在激活的事务现象,主要原因是由于咋Spring管理事务中current session是绑定下springsessioncontext中的,而不是绑定在threadlocalsessioncontext中的。
hibernate.current_session_context_class常用3种配置:jta,thread,org.springframework.orm.hibernate4.SpringSessionContext
hibernate.current_session_context_class=thread
实质是:
hibernate.current_session_context_class= org.hibernate.context.internal.ThreadLocalSessionContext
org.hibernate.context.internal.ThreadLocalSessionContext -
当前session通过当前执行的线程来跟踪和界定。
同理:
hibernate.current_session_context_class=jta
实质是:
hibernate.current_session_context_class= org.hibernate.context.internal.JTASessionContext
org.hibernate.context.internal.JTASessionContext-
当前session根据JTA来跟踪和界定。这和以前的仅支持JTA的方法是完全一样的。
同理
hibernate.current_session_context_class=org.springframework.orm.hibernate4.SpringSessionContext
实质是
Spring @Transactional声明式事务管理,”currentSession”的定义为: 当前被 Spring事务管理器 管理的Session,此时应配置:
hibernate.current_session_context_class=org.springframework.orm.hibernate4.SpringSessionContext
spring 整合hibernate管理事务后,由Spring的TransactionManager管理事务后, currentSession是绑定到SpringSessionContext的,而不是thread。
此时hibernate.current_session_context_class应该是SpringSessionContext,而它又会在使用LocalSessionFactoryBean时自动的设置。
所以就不需要你去设置current_session_context_class
原来配置事务模式:
<prop key="hibernate.current_session_context_class">thread</prop>
会出现不存在激活的事务现象,主要原因是由于咋Spring管理事务中current session是绑定下springsessioncontext中的,而不是绑定在threadlocalsessioncontext中的。
hibernate.current_session_context_class常用3种配置:jta,thread,org.springframework.orm.hibernate4.SpringSessionContext
hibernate.current_session_context_class=thread
实质是:
hibernate.current_session_context_class= org.hibernate.context.internal.ThreadLocalSessionContext
org.hibernate.context.internal.ThreadLocalSessionContext -
当前session通过当前执行的线程来跟踪和界定。
同理:
hibernate.current_session_context_class=jta
实质是:
hibernate.current_session_context_class= org.hibernate.context.internal.JTASessionContext
org.hibernate.context.internal.JTASessionContext-
当前session根据JTA来跟踪和界定。这和以前的仅支持JTA的方法是完全一样的。
同理
hibernate.current_session_context_class=org.springframework.orm.hibernate4.SpringSessionContext
实质是
Spring @Transactional声明式事务管理,”currentSession”的定义为: 当前被 Spring事务管理器 管理的Session,此时应配置:
hibernate.current_session_context_class=org.springframework.orm.hibernate4.SpringSessionContext
spring 整合hibernate管理事务后,由Spring的TransactionManager管理事务后, currentSession是绑定到SpringSessionContext的,而不是thread。
此时hibernate.current_session_context_class应该是SpringSessionContext,而它又会在使用LocalSessionFactoryBean时自动的设置。
所以就不需要你去设置current_session_context_class
相关文章推荐
- hibernate.current_session_context_class 的各个取值的区别以及与Spring整合的问题
- hibernate的current_session_context_class配置
- hibernate.current_session_context_class属性配置
- hibernate_current_session_context_class 配置
- spring事务配置Caused by: java.lang.ClassNotFoundException: org.hibernate.engine.SessionFactoryImplemento
- Hibernate current_session_context_class的事务说明
- spring和hibernate整合出错java.lang.NoClassDefFoundError: org/hibernate/context/spi/CurrentSessionContex
- 还是spring中hibernate.current_session_context_class问题
- Hibernate配置文件current_session_context_class的意思
- Hibernate配置文件current_session_context_class的意思
- java综合(六)hibernate.current_session_context_class配置
- spring与hibernate的整合问题—Spring的配置文档applicationContext.xml
- spring hibernate整合时配置文件的事务部分(spring管理事务)
- Spring和HIbernate整合配置数据源 出现 'java.lang.String'不能转换为java.lang.class
- Hibernate与Spring整合的一些配置问题(一)——LocalSessionFactoryBean
- hibernate.current_session_context_class 比较权威的解释
- Spring整合hibernate No Session found for current thread
- spring整合hibernate(注解、xml)applicationContext.xml配置
- spring、hibernate整合核心配置文件applicationContext.xml
- spring 管理事务配置时,结果 报错: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here这个异常