Here is the relevant configuration. It's pretty simple though it seems to be a little out-of-the-box. Hibernate and Spring JTA aren't exactly aware of each other. I'm expecting Hibernate to pick up the Spring JTA by using the common name 'UserTransaction.'
Here is the app context for spring:
Code:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<!-- This is the EJB-centric application context that will be loaded by -->
<!-- the Spring bean factory locator -->
<beans>
<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="userTransactionName">
<value>UserTransaction</value>
</property>
</bean>
<bean id="userAdminService"
singleton="true"
class="com.xxx.service.OdinUserAdminService"/>
...other beans...
<!-- Transaction Interceptor set up to do PROPAGATION_REQUIRED on all methods -->
<bean id="matchAllWithPropReq"
class="org.springframework.transaction.interceptor.MatchAlwaysTransactionAttributeSource">
<property name="transactionAttribute">
<value>PROPAGATION_NESTED</value>
</property>
</bean>
<bean id="matchAllTxInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager">
<ref bean="transactionManager"/>
</property>
<property name="transactionAttributeSource">
<ref bean="matchAllWithPropReq"/>
</property>
</bean>
<!-- One BeanNameAutoProxyCreator handles all beans where we want all methods to use PROPAGATION_REQUIRED -->
<bean id="autoProxyCreator" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="interceptorNames">
<list>
<idref local="matchAllTxInterceptor"/>
</list>
</property>
<property name="beanNames">
<list>
<idref local="userAdminService"/>
...other beans...
</list>
</property>
</bean>
</beans>
Here is the HibernateService that returns the SessionFactory. We have a utility class that looks up the HibernateFactory service via JNDI.
Code:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE server PUBLIC "-//JBoss//DTD MBean Service 3.2//EN" "http://www.jboss.org/j2ee/dtd/jboss-service_3_2.dtd">
<server>
<mbean code="net.sf.hibernate.jmx.HibernateService" name="jboss.jca:service=HibernateFactory,name=HibernateFactory">
<attribute name="JndiName">java:/hibernate/HibernateFactory</attribute>
<attribute name="Datasource">java:/OracleDS</attribute>
<attribute name="Dialect">net.sf.hibernate.dialect.Oracle9Dialect</attribute>
<!--attribute name="Datasource">java:/DefaultDS</attribute-->
<!--attribute name="Dialect">net.sf.hibernate.dialect.HSQLDialect</attribute-->
<attribute name="MapResources">
com/renewdata/odin/dao/mappings/OdinUser.hbm.xml,
...more mappings...
</attribute>
<attribute name="TransactionStrategy">net.sf.hibernate.transaction.JTATransactionFactory</attribute>
<attribute name="TransactionManagerLookupStrategy">net.sf.hibernate.transaction.JBossTransactionManagerLookup</attribute>
<attribute name="UserTransactionName">UserTransaction</attribute>
<attribute name="ShowSql">false</attribute>
<attribute name="CacheProvider">net.sf.hibernate.cache.EhCacheProvider</attribute>
<depends>jboss.jca:service=RARDeployer</depends>
<!-- Make it deploy ONLY after DataSource had been started -->
<depends>jboss.jca:service=LocalTxCM,name=OracleDS</depends>
<!--depends>jboss.jca:service=LocalTxCM,name=DefaultDS</depends-->
</mbean>
</server>
I would expect Hibernate to listen for the Transaction to commit() and then flush the Session, but this doesn't seem to be happening, even when I specify FlushMode.COMMIT. The server log shows each service method being committed but the database is never being modified.
Code:
2005-07-11 15:39:52,093 DEBUG [org.springframework.transaction.interceptor.TransactionInterceptor] Invoking commit for transaction on method 'getConfiguration' in class [com.renewdata.odin.service.IOdinUserAdminService]
I'm confident that Hibernate is using the Spring Transaction because calling commit() programatically generates a warning that I'm inside a Managed Transaction.
Any help would be appreciated. Thanks!