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:
http://it-essence.xs4all.nl/roller/technology/entry/transactions_over_multiple_jpa_persistence

Persistence Unit from persistence.xml:
<persistence-unit name="jta" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<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" />
</properties>
</persistence-unit>

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">
<props>
<prop key="URL">${database.url}</prop>
<prop key="user">${database.username}</prop>
<prop key="password">${database.password}</prop>
</props>
</property>
<property name="poolSize" value="20" />
</bean>

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

<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>

<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" />
</bean>

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?

Thanks
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!

Cheers
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