jump to navigation

Enhydra XA DataSource September 30, 2008

Posted by Phill in General J2EE.
Tags: , ,
comments closed

Just a quick follow up to my last post. xapool.jar comes included with JOTM. I just used the version of xapool which came with it… however, we’ve been having a number of impossible to reproduce problems where the data access layer throws an exception “Connection Closed”.

It turns out that the version of xapool.jar which is included with JOTM is out of date! I’d suggest switching to a newer version – 1.5.0 is the latest stable version, or there’s 1.6 beta.

I unfortunately can’t say for sure whether it has fixed the issue (due to its rather random nature), but it’s probably worth being on the newer version anyway.

Update: it didn’t fix the problem, or at least we had similar problems with it. I would not recommend using the Enhydra connection pool.

Spring Transactions across multiple datasources September 16, 2008

Posted by Phill in Other Stuff, Spring.
Tags: , , , ,
comments closed

Update: Since writing this post I have discovered problems with the Enhydra connection pool, and as such I do not recommend using it. I recommend finding another way to accomplish what you want to do.

We have an application here which connects to two different data sources. I was having problems getting the application to be transactional using Springs @Transactional annotation. The problem is, the Transactional annotation does not let you specify a transaction manager – and one transaction manager can only manage one DataSource. Or so I thought.

It turns out that it is possible, using JTA – and JOTM.

The configuration you need is pretty minimal. In your application context XML file, you need to put the following:

<bean id="jotm"
class="org.springframework.transaction.jta.JotmFactoryBean" />

<bean id="innerDataSource"
<property name="transactionManager" ref="jotm" />
<property name="driverName" value="${dataSource.driver}" />
<property name="url" value="${dataSource.url}" />
<property name="user" value="${dataSource.username}" />
<property name="password" value="${dataSource.password}" />

<bean id="dataSource"
<property name="dataSource" ref="innerDataSource" />
<property name="user" value="${dataSource.username}" />
<property name="password" value="${dataSource.password}" />

<bean id="transactionManager"
<property name="userTransaction" ref="jotm" />

(You also need to set up your libraries to inculde JOTM and the XA Data Sources – which can be got here)

This is for the first DataSource. Your second DataSource should be set up as per the above, except that you don’t need to repeat the jotm or transactionManager beans.

Provided that you then set up your transactions as annotation-driven – and actually use a few annotations – you should find your methods are transactional across multiple dataSources!

You may also find it helps to read a couple of articles on the subject, two which I found helpful are here and here.