As I mentioned before, I have my Oracle XE XA* datasource deployed, and the Spring bean configured to do the JNDI lookup. My next question was, what about the Hibernate session factory — how do I transition that from one dealing only with local Hibernate transactions, to one that participates in global XA transactions?
What I have for my Hibernate session factory bean is something like this:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource" ref="myDataSource" /> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop> <prop key="hibernate.hbm2ddl.auto">create</prop> </props> </property> <property name="mappingResources"> <list> <value>com/example/SimplePerson.hbm.xml</value> </list> </property> </bean>
I looked in the Spring manual (possibly the best-written technical manual I’ve seen, by the way), and in Section 12.2.8. Transaction management strategies there is this:
Simply replace the Hibernate transaction manager with Spring’s JTA transaction implementation.
And farther down…
For distributed transactions across multiple Hibernate session factories, simply combine JtaTransactionManager as a transaction strategy with multiple LocalSessionFactoryBean definitions.
The second quote just helps convince me that yes, even though I’m using a org.springframework.orm.hibernate3.LocalSessionFactoryBean, sessions from that factory should be able to participate in XA transactions as long as the dataSource is an XA datasource.
Next time we’ll deploy a project that gets both a JMS ConnectionFactory and a JDBC datasource, via JNDI, from the app server.
*Would you pronounce that X-E-X-A, zeezah, or guhZEE guhZAH? :)