jhoeller wrote:
Since Spring 1.0.1, HibernateTemplate and SessionFactoryUtils auto-detect an ongoing JTA respectively EJB CMT transaction, and automatically provide a transaction-scoped Hibernate Session for it - without Spring's JtaTransactionManager being involved (so also no TransactionProxyFactoryBean definitions necessary).
Yes, I got this working last Friday and it is extremely helpful in keeping separation of concerns between the two layers. Very nice! However, the statement above is confusing when relating back to section 7 of your article posted on this site. My understanding is that you neede JtaTransaction manager, but are you suggesting I can just use HibernateTransaction Manager? I posted my current applicationContext below. It seems to work with either one for me, but I want to use this properly.
Also, I was able to leverage the convenience methods off getHibernateTempate() without having to use the SessionUtils explicitly. I'm assuming that you use the same calls under the covers. Again, very nice!
Thanks,
Lou
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="clmDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName"><value>jdbc/clmDataSource</value></property>
</bean>
<bean id="mySessionFactory"
class="org.springframework.orm.hibernate.LocalSessionFactoryBean">
<property name="dataSource">
<ref local="clmDataSource"/>
</property>
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
</bean>
<bean id="myTransactionManager"
class="org.springframework.transaction.jta.JtaTransactionManager"/>
<!-- ******** Are you saying you should use this one instead?? -->
<!--<bean id="myTransactionManager"
class="org.springframework.orm.hibernate.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="mySessionFactory"/>
</property>
</bean>-->
<bean id="myHibernateInterceptor"
class="org.springframework.orm.hibernate.HibernateInterceptor">
<property name="sessionFactory">
<ref bean="mySessionFactory"/>
</property>
</bean>
<bean id="clmClaimDaoTarget" singleton="false"
class="com.mitchell.services.technical.claim.dao.spring.ClmClaimHibernateDao">
<property name="sessionFactory">
<ref local="mySessionFactory"/>
</property>
</bean>
<bean id="clmClaimDao"
class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="proxyInterfaces">
<value>com.mitchell.services.technical.claim.dao.ClmClaimDao</value>
</property>
<property name="interceptorNames">
<list>
<value>myHibernateInterceptor</value>
<value>clmClaimDaoTarget</value>
</list>
</property>
</bean>
<bean id="claimDaoManager"
<property name="clmClaimDao">
<ref local="clmClaimDao"/>
</property>
</bean>
</beans>
hibernate.cfg.xml:
Code:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration
PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">
<hibernate-configuration>
<session-factory name="ClmSessionFactory">
<property name="dialect">net.sf.hibernate.dialect.Oracle9Dialect</property>
<property name="hibernate.max_fetch_depth">3</property>
<property name="hibernate.jdbc.batch_size">0</property>
<property name="hibernate.jdbc.use_get_generated_keys">true</property>
<property name="hibernate.jdbc.use_streams_for_binary">true</property>
<property name="hibernate.show_sql">false</property>
<property name="hibernate.use_outer_join">true</property>
<property name="hibernate.cglib.use_reflection_optimizer">true</property>
<property name="hibernate.query.substitutions">true 'T', false 'F', yes 'Y', no 'N'</property>
<property name="hibernate.transaction.manager_lookup_class">
net.sf.hibernate.transaction.WeblogicTransactionManagerLookup
</property>
<mapping
resource="com/mitchell/services/technical/claim/dao/vo/ClmClaim.hbm.xml"
/>
</session-factory>
</hibernate-configuration>