The beans, the beans, the Hibernate beans…

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?  :)

Advertisements

, ,

  1. #1 by Ian on January 30, 2009 - 6:30 pm

    Hi,

    Does Oracle 10g XE really support XA transaction? I tried to run a combination Spring 2.5, Hibernate 3, Weblogic 9.2 and Oracle 10g XE and couldn’t get the XA transaction to work.

  2. #2 by danielmeyer on February 2, 2009 - 8:51 am

    Ian,
    I used Spring’s <tx:jta-transaction-manager /> bean with Spring 2.5, Hibernate 3, JBoss 4.2.2.GA and Oracle 10g. Spring should be able to find Weblogic’s JTA transaction manager, and if Spring couldn’t find it you’d get an error at the time your project was deployed to the app server — Spring would complain that it couldn’t find UserTransaction (or TransactionManger maybe). What error were you getting?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s