How to spring manage hibernate session lifecycle

Spring is used in our Java EE project team, and hibernation is used for basic ORM.

transactionManager is installed as follows:

<bean id="transactionManager"  class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean> 

sessionFactory is set as follows:

<bean id="sessionFactory"  class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan"
value="com.company.model" />
<property name="hibernateProperties">

<value>
hibernate.dialect=org.hibernate.dialect.Oracle10gDialect
hibernate.show_sql=true
hibernate.jdbc.fetch_size=50
</value>
</property>
</bean>

my quesiton defines the whole setting, I have not seen any property settings for the hibernate session life cycle. Context sessions were introduced in the hibernate help system, and he said that there are three implementations of CurrentSessionContext.

  • JTA 2.Thread 3.Managed

How to find out which implementation was used. Maybe Spring, but I have no idea.

+3
source share
2 answers

SessionFactory Spring . Hibernate SessionFactory.getCurrentSession(). , , commit() rollback(), ( ). Hibernate factory /, , . CurrentSessionContext, HibernateTransactionManager. jta-: "JtaTransactionManager" .

+3

hibernate.current_session_context_class , org.hibernate.context.CurrentSessionContext . , , org.hibernate.transaction.TransactionManagerLookup, Hibernate org.hibernate.context.JTASessionContext., , "jpa".

, 'jpa' - , , .

<prop key="hibernate.current_session_context_class">managed</prop>

.

http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/architecture.html#architecture-current-session

0

All Articles