Atomikos Forum

SpringSource tc Server + Atomikos + Hibernate JPA Success

I spent quite a bit of time struggling with getting Atomikos to integrate with Hibernate as a JPA provider in a simple environment, such as tomcat.  Since there are a few posts that deal with this issue and none that I saw provide a complete solution, I figured I would let people know how I got it working.  I am by no means an expert, so there could definitely be some problems with what I've done (let me know if there are), but it appears to be working well.

Much of what I did is actually based on this post:

Persistence Unit from persistence.xml:
<persistence-unit name="jta" transaction-type="JTA">
<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle9iDialect" />
<property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.ImprovedNamingStrategy" />
<property name="hibernate.transaction.manager_lookup_class" value="com.atomikos.icatch.jta.hibernate3.TransactionManagerLookup" />

Applicable bean definitions of applicationContext.xml
<bean id="xaDataSource"class="com.atomikos.jdbc.AtomikosDataSourceBean" init-method="init" destroy-method="close">
<qualifier value="atomikosDataSource" />
<property name="uniqueResourceName" value="xaDataSource" />
<property name="xaDataSourceClassName" value="${database.datasource.class}" />
<property name="xaProperties">
<prop key="URL">${database.url}</prop>
<prop key="user">${database.username}</prop>
<prop key="password">${database.password}</prop>
<property name="poolSize" value="20" />

<bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" id="jtaEntityManagerFactory">
<property name="dataSource" ref="xaDataSource" />
<property name="persistenceUnitName" value="jta" />

<tx:annotation-driven mode="aspectj" />

<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="transactionManager" ref="atomikosTransactionManager" />
<property name="userTransaction" ref="atomikosUserTransaction" />
<qualifier value="jta" />

<bean id="userTransactionService" class="com.atomikos.icatch.config.UserTransactionServiceImp" init-method="init" destroy-method="shutdownForce" />

<bean id="atomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager" depends-on="userTransactionService" />

<bean id="atomikosUserTransaction" class="com.atomikos.icatch.jta.UserTransactionImp" depends-on="userTransactionService">
<property name="transactionTimeout" value="300" />

I also got a JMS resource in the mix, and if I turn up spring/atomikos logging I can see transactions committing/rolling back appropriately.
John Garrison Send private email
Thursday, August 19, 2010
Thanks very much, John!

What version(s) of each product did you use?

Guy Pardon Send private email
Friday, August 20, 2010
Hibernate: 3.5.0-Final
Spring: 3.0.2.RELEASE
Atomikos: 3.6.4
John Garrison Send private email
Monday, August 23, 2010
Thanks again,

This was one of the main complaints we had so far - lack of JPA samples. I am sure this will make good stuff for our wiki and docs!

Guy Pardon Send private email
Monday, August 30, 2010

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics