using current_session_context_class property hibernate 3 hibernate 4
Ich habe eine Anwendung mit Spring und Hibernate3, die gut in der Produktion läuft. Es folgt die Konfiguration für die Sitzungsfactory in der Datei applicationContext.xml von Spring
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mappingDirectoryLocations">
<list>
<value>classpath:/hibernate</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect
</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.use_sql_comments">true</prop>
<prop key="hibernate.max_fetch_depth">2</prop>
<prop key="hibernate.autocommit">false</prop>
<prop key="hibernate.current_session_context_class ">thread</prop>
<prop key="hibernate.generate_statistics">true</prop>
<prop key="hibernate.jdbc.batch_size">20</prop>
</props>
</property>
</bean>
<bean id="txManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- the transactional advice (what 'happens'; see the <aop:advisor/> bean
below) -->
<tx:advice id="txAdvice" transaction-manager="txManager">
<!-- the transactional semantics... -->
<tx:attributes>
<tx:method name="*" propagation="REQUIRED" />
<tx:method name="get*" propagation="SUPPORTS" read-only="true" />
<tx:method name="count*" propagation="SUPPORTS" read-only="true" />
<tx:method name="validate*" propagation="SUPPORTS"
read-only="true" />
<tx:method name="find*" propagation="SUPPORTS" read-only="true" />
<tx:method name="login" propagation="SUPPORTS" read-only="true" />
</tx:attributes>
</tx:advice>
<!-- ensure that the above transactional advice runs for any execution of
an operation defined by the service interfaces -->
<aop:config>
<aop:pointcut id="projectServiceOperation"
expression="execution(* com.service.project.IProjectService.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="projectServiceOperation" />
</aop:config>
Es funktioniert gut in der Produktion.
Jetzt migrieren wir für ein anderes Projekt auf Hibernate4. Wir haben dieselbe Konfiguration kopiert, außer dass SessionFactory, TransacionManager usw. von Hierrnate 4 aus dem org.springframework.orm.hibernate4. * -Paket verwendet wurden. Es gab jedoch eine Ausnahme mit der Meldung "Speichern ist ohne aktive Transaktion nicht gültig". Nach einigem Suchen schienen viele Leute mit den Problemen konfrontiert zu sein, und einige Leute schlugen vor, sie nicht zu verwenden
<prop key="hibernate.current_session_context_class ">thread</prop>
Eigentum und es hat funktioniert. Es hat auch bei mir funktioniert. Alle kleinen Informationen, die ich aus den Posts sammeln konnte, beziehen sich auf kontextbezogene Sitzungen und Thread-Strategien, die die Sitzungsverwaltungsstrategie von Spring beeinträchtigen. Aber nein, wo konnte ich eine konkrete Antwort finden. Warum funktionierte es auch mit Hibernate3 und nicht mit Hibernate4? Was ist der Unterschied und was hat sich geändert? Jede andere Konfiguration ist gleich. Ich benutze nicht @Transactional, sondern die alte XML-Methode.
Can somebody point me to clear explaination for this behavioural difference in Hibernate3 and Hibernate4?