My Quotes


When U were born , you cried and the world rejoiced
Live U'r life in such a way that when you go
THE WORLD SHOULD CRY






Tuesday, June 3, 2014

Atomikos Spring and Tomcat7 JPA integration



Create the JTA specific LDAP datasource (OR) you can very well use regular datasource spring beans.
When you create the datasoruce make sure it has only the following properties

Java Factory:com.atomikos.tomcat.EnhancedTomcatAtomikosBeanFactory
 Java Class:com.atomikos.jdbc.AtomikosDataSourceBean
 URL: jdbc:oracle:thin:@hostname:port/SID
 Driver ClassName: oracle.jdbc.driver.OracleDriver
 maxPoolSize  10
 uniqueResourceName jdbc/myJTA (this is the name you give in your spring config and context.xml file)
xaDataSourceClassName oracle.jdbc.xa.client.OracleXADataSource


Define this datasource in your META-INF\Context.xml file




Change the ojdbc driver version just in case in your pom.xml file

com.oracle
ojdbc6
11.1.0.7.0


Add the following for JTA in your pom.xml file


org.springframework.data
spring-data-jpa
1.3.2.RELEASE


javax.transaction
jta
1.1



org.aspectj
aspectjrt
1.6.9


org.aspectj
aspectjweaver
1.6.9


cglib
cglib
2.2





com.atomikos
atomikos-parent
3.8.0
pom


com.atomikos
atomikos-util
3.8.0


com.atomikos
transactions-api
3.8.0


com.atomikos
transactions-jdbc
3.8.0


com.atomikos
transactions-jms
3.8.0


com.atomikos
transactions-jta
3.8.0


com.atomikos
transactions-hibernate3
3.8.0


com.atomikos
transactions
3.8.0


com.atomikos.tomcat
atomikos-integration-extension
3.7.1-201303261


xjp
xjp.ldap.tomcat
1.2.1






Spring JMS changes
Add the property for your jmsTemplate which needs to be as part of the transaction. For example my spring config will look like as below







false











Sprring data changes

Note that JPA and CONTEXT should be before TX

Add the following




Add the bean for the data source spring bean

   
   
   
       
    myuserid
    mypwd
    jdbc:oracle:thin:@host:port:SID
       
   
   
  

or it could be as simple as referencing from META-INF\Context.xml file

  
  
 


CONSTRUCT ATOMIKOS USERTRANSACTIONMANAGER, NEEDED TO CONFIGURE SPRING

 
  
 

 
  
 

 
 
  
  
  
 

LEAVE THE TRANSACTION MANAGER to "org.springframework.orm.jpa.JpaTransactionManager"

  
 


If you try to switch the transaction manage transaction manager to "jtaTransactionManager" you will get exceptions stating "Transaction is not in progress".
The only way to associate the atomikos transaction manager to that of the JPA Entity Manager is to add the following tag

  



Now is the beauty . Way to associate the the JTA for a resource like Spring Batch
Change this


to

    
    
  
 


Just as a piece, Atomikos will normally use annoying loggers. To prevent this add the following property in your log4j.properties
log4j.logger.com.atomikos=WARN


Lastly you can annotate the java files as usual with the regular annotations
@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false, rollbackFor = { Exception.class })

No comments :