Home Liferay JTA Integration with Liferay Tomcat Using JOTM
formats

JTA Integration with Liferay Tomcat Using JOTM

Liferay Version : 6.0.6 CE Tomcat

LR Gurus,

For any enterprise level of application, Transaction is most important thing to create reliability and generate faith in users towards application. If it fails to do so it will loose popularity.

Overview:

Recently we have faced such situation in one of our project where we were updating multiple services, some of them were portal services like groups, roles, journal-article and others, and rest of them were our custom developed services (using service builder). There are bunch of issues we faced and we are sure many of you have facing the same,

  • By default Liferay supports Hibernate Transaction Manager which do not supports distributed transaction management. It means when objects from different contexts are updating , Hibernate Transaction Manager is not able cope with that. Only portal objects are getting roll backed when exception is thrown.
  • In our case we are updating objects from portal services and custom objects from portlet level services are in different contexts.
  • Liferay supports JTA transaction manager which able to handle distributed transaction management. Good to hear that!!! But now the problem is that Tomcat doesn’t support JTA directly.
  • JOTM is the solution to integrate JTA transaction manager with Tomcat. In our case we are using Liferay Tomcat.

Steps:

  • Need to enable following properties in portal-ext.properties. We are using JNDI configuration for database connection.

transaction.manager.impl=org.springframework.transaction.jta.JtaTransactionManager

transaction.manager.property.allowCustomIsolationLevels=true

jdbc.default.jndi.name=jdbc/LiferayPool

This will indicate the Liferay to use JTA transaction manager rather than the default one

  • Modify your context.xml for JNDI configuration like this,

<Resource name=”UserTransaction”
auth=”Container”
type=”javax.transaction.UserTransaction” />

<Transaction factory=”org.objectweb.jotm.UserTransactionFactory”
jotm.timeout=”60″ />

<Resource
name=”jdbc/LiferayPool”
auth=”Container”
type=”javax.sql.DataSource”
driverClassName=”com.mysql.jdbc.Driver”
url=”jdbc:mysql://localhost/lportal?useUnicode=true&amp;characterEncoding=UTF-8&amp;useFastDateParsing=false”
username=”root”
password=””
factory=”org.objectweb.jotm.datasource.DataSourceFactory”
maxActive=”20″
max-connections=”100″
/>

  • Basically one needs to change the type with javax.sql.DataSource and factory with org.objectweb.jotm.datasource.DataSourceFactory. Here DataSourceFactory class part of JOTM liberaries. We need to put several jars in Tomcat
  • Here we have attached the zip of jar files which needs to be unzipped and one need to copy all the jars and put into global lib directory of Tomcat {TOMCATE_HOME}/lib/ext/
  • Once all the steps followed one has to restart the Liferay Tomcat and look for any errors.
  • If no error while startup that means JTA has been integrated successfully. Now your transaction should rollback all the objects in case of any exception.

We hope that this blog post will help you to solve biggest architecture level issue. Feel free to contact us Liferay portal development companies at info@scalsys.com in case of any queries.

Thanks & Regards,

ScalSys Team

attachments

 

Share!Share on FacebookShare on Google+Share on LinkedInTweet about this on TwitterFlattr the authorDigg thisPin on PinterestEmail this to someoneShare on StumbleUponShare on RedditShare on TumblrBuffer this pagePrint this page
Tags:
Comments Off on JTA Integration with Liferay Tomcat Using JOTM.
Copyright © 2017 - Scalsys. All Rights Reserved