Tomcat 7 with full JTA

Everytime I clean my home directory I purge something important.

Just like a week week ago when I  realized my Tomcat 7 installation was gone and with it all the things I had to do to get JOTM running in there.

Once again I spent a while to get everything back together.
But THIS time I am writing it down.

Tomcat Setup

So I want to have Tomcat 7 with full JTA (should also work on older Tomcat versions).
I will be using JOTM as it provides everything I need.

After downloading the JOTM-distribution copy the following jars to <tomcat-home>/lib.

  • commons-logging-api.jar
  • jotm-core.jar
  • log4j.jar
  • ow2-connector-1.5-spec.jar
  • ow2-jta-1.1-spec.jar
I will also add the tomcat connection pool to show a full example later on.
Download the distribution and add the following jars to <tomcat-home>/lib.
  • tomcat-jdbc.jar
  • tomcat-juli.jar

JNDI

Now we need to tell Tomcat how to create the required JNDI-resources.

Note:
Everything created using the Resource-tag will end up in java:comp/env/. Tomcat doesn’t provide functionality to put it somewhere else (or I was simply too blind to find it).

To make resources available we need to edit <tomcat-home>/conf/context.xml.
The first thing we need to add is a connection pool to showcase the useage of JTA later on.

<ResourceLink global="jdbc/myDB" name="jdbc/myDB" type="javax.sql.DataSource"/>
<Resource
	driverClassName="org.h2.Driver"
	factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
	name="jdbc/myDB"
	password=""
	type="javax.sql.DataSource"
	url="jdbc:h2:tcp://localhost/~/test"
	username="sa"/>

Now we need to add the actual JTA-related resources, starting with the the TransactionSynchronizationRegistry.
Remembering what I wrote above we have to be aware that the TransactionSynchronizationRegistryFactory will end up at java:comp/env/TransactionSynchronizationRegistry and not at java:comp/TransactionSynchronizationRegistry as the JEE-spec requires.
More on that later.

<Resource
	name="TransactionSynchronizationRegistry"
	auth="Container"
	type="javax.transaction.TransactionSynchronizationRegistry"
	factory="org.objectweb.jotm.TransactionSynchronizationRegistryFactory"/>

The final step is to add the actual transaction manager. In older versions of Tomcat one had to register the JTA-factory as a resource.
Today we got a specialized tag for that.

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

The main difference between the Transaction-tag and the Resource-Tag is that the transaction manager will end up at java:comp/UserTransaction, which is the name required by JEE.
That’s it for installing the JOTM as JTA-provider in Tomcat.

To make things available in the web application we need to add a couple of lines to web.xml in our webapplication.

<resource-env-ref>
	<description>DB Connection </description>
	<resource-env-ref-name>jdbc/myDB</resource-env-ref-name>
	<resource-env-ref-type>javax.sql.DataSource</resource-env-ref-type>
</resource-env-ref>

<resource-env-ref>
	<description>JTA transaction manager</description>
	<resource-env-ref-name>jta/UserTransaction</resource-env-ref-name>
	<resource-env-ref-type>javax.transaction.UserTransaction</resource-env-ref-type>
</resource-env-ref>

<resource-env-ref>
	<description>JTA Transaction Synchronization Registry</description>
	<resource-env-ref-name>TransactionSynchronizationRegistry</resource-env-ref-name>
	<resource-env-ref-type>javax.transaction.TransactionSynchronizationRegistry</resource-env-ref-type>
</resource-env-ref>

Putting it all together

A little example on how to use JTA in your webapplication via spring:

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
	<property name="dataSource" ref="dataSource"/>
	<property name="jpaVendorAdapter">
		<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
			<property name="showSql" value="false"/>
		</bean>
	</property>
	<propertyname="jpaProperties">
		<props>
			<prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</prop>
		</props>
	</property>
</bean>

<jee:jndi-lookup id="dataSource" jndi-name="java:comp/env/jdbc/myDB" resource-ref="true"/>

<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
	<property name="transactionSynchronizationRegistryName" value="java:comp/env/TransactionSynchronizationRegistry"/>
	<property name="transactionManagerName" value="java:comp/UserTransaction"/>
</bean>

The only thing I don’t really like about this configuration is this line:

<property name="transactionSynchronizationRegistryName" value="java:comp/env/TransactionSynchronizationRegistry"/>

This is no problem, as long as your only deployment target is Tomcat.

If Tomcat  is only used for local deployments for development and the production system is some sort of JEE-server you will have to change the JNDI-location to the JEE-default.

This is easily achieved using maven-profiles.

Advertisements

About codepitbull
A nerd, a geek, a software developer. Oh, and married ;)

14 Responses to Tomcat 7 with full JTA

  1. Jvm Host says:

    Thanks for the article! JOTM moved to jotm.ow2.org

  2. Steve Hiller says:

    HI CPB,

    Thanks for taking the time to write this blog entry — it’s precise and to the point. I have followed your directions but I am having an issue, which you alluded to:

    Caused by: org.springframework.transaction.TransactionSystemException: JTA TransactionManager is not available at JNDI location [java:comp/UserTransaction]; nested exception is javax.naming.NamingException: Cannot create resource instance

    Any ideas what might be happening?

    Thanks in advance,
    Steve Hiller
    Ft. Lauderdale, FL

  3. Steve Hiller says:

    Nevermind, I resolved the issue by moving configurations from server.xml to context.xml. Thanks!

  4. Mihir Parekh says:

    Hello Sir,
    for nice article. I have one question here. if i want to use it with Simple Java class Using InitialContext, How can i use it ?? right now i am having an exception “resource can not be created.”

  5. Pingback: Transação Composta JTA com Spring e Tomcat | Fernando Franzini Java Blog

  6. Fernando Franzini says:

    It seems to me that this missing a setting in your article. Where you set the “jta / UserTransaction”. Where you set up this jndi?

  7. Matias says:

    And to access to the data do you access this way:
    @PersistenceContext
    private EntityManager entityManager;

    or this way:

    InitialContext initCtxt = new InitialContext();
    Context envcon=initCtxt.lookup(“java:/comp/env”);
    Datasource=envcon.lookup(“jdbc/dsTCS09”);
    InitialContext ctx = new InitialContext();
    UserTransaction transaction = (UserTransaction)ctx.lookup(“java:comp/UserTransaction”);

  8. Ashish says:

    I tried it, but facing an issue if someone can help..here is the part of my console

    10512 [http-bio-8080-exec-10] DEBUG com.fhl.ClientInformationPage$1 {} – check1
    10533 [http-bio-8080-exec-10] ERROR org.ofbiz.core.entity.config.EntityConfigUtil$DatasourceInfo {} – Could not parse constraint-name-clip-length value for datasource with name jdbc2/TestDB, using default value of 30
    10541 [http-bio-8080-exec-10] DEBUG org.objectweb.jotm.UserTransactionFactory {} – UserTransactionFactory.getObjectInstance
    10549 [http-bio-8080-exec-10] DEBUG org.objectweb.jotm.Batch {} – Batch constructor
    10549 [http-bio-8080-exec-10] DEBUG org.objectweb.jotm.Clock {} – Clock constructor
    10553 [http-bio-8080-exec-10] DEBUG org.objectweb.jotm.TransactionRecoveryImpl {} – TransactionRecoveryImpl constructor
    10553 [http-bio-8080-exec-10] DEBUG org.objectweb.jotm.TransactionRecoveryImpl {} – JOTM Recovery is disabled
    10553 [http-bio-8080-exec-10] DEBUG org.objectweb.jotm.Current {} – default timeout= 60
    10553 [http-bio-8080-exec-10] DEBUG org.objectweb.jotm.UserTransactionFactory {} – UserTransactionFactory.getObjectInstance ut= org.objectweb.jotm.Current@45cd14f7
    10554 [http-bio-8080-exec-10] DEBUG org.objectweb.jotm.Current {} – Current.getStatus(): NO_TRANSACTION
    10558 [http-bio-8080-exec-10] DEBUG org.objectweb.jotm.TransactionImpl {} – xid= bb14:38:0:0167c3b03eed884b3d…a9ec01:
    10558 [http-bio-8080-exec-10] DEBUG org.objectweb.jotm.TransactionImpl {} – timeout= 60
    10560 [http-bio-8080-exec-10] DEBUG org.objectweb.jotm.InternalTransactionContext {} – xid=bb14:38:0:0167c3b03eed884b3d…a9ec01:, timeout=60
    10560 [http-bio-8080-exec-10] DEBUG org.objectweb.jotm.Current {} – new tx=bb14:38:0:0167c3b03eed884b3d…a9ec01:
    10561 [http-bio-8080-exec-10] DEBUG org.objectweb.jotm.TransactionImpl {} – TransactionImpl.doAttach flag= TMJOIN
    10561 [http-bio-8080-exec-10] DEBUG org.objectweb.jotm.TransactionImpl {} – number of enlisted= 0
    10562 [http-bio-8080-exec-10] DEBUG org.objectweb.jotm.Current {} – threadTx set to bb14:38:0:0167c3b03eed884b3d…a9ec01:
    10562 [http-bio-8080-exec-10] DEBUG org.objectweb.jotm.Current {} – Associate tx to xid (xid=bb14:38:0:0167c3b03eed884b3d…a9ec01:) tx =bb14:38:0:0167c3b03eed884b3d…a9ec01:
    10563 [http-bio-8080-exec-10] DEBUG org.objectweb.jotm.TimerEvent {} – TimerEvent.new(bb14:38:0:0167c3b03eed884b3d…a9ec01:,60,null,false)
    10563 [http-bio-8080-exec-10] DEBUG org.objectweb.jotm.TransactionImpl {} – set timer for tx (timer=org.objectweb.jotm.TimerEvent@698df4bf, tx=bb14:38:0:0167c3b03eed884b3d…a9ec01:)
    10563 [http-bio-8080-exec-10] DEBUG org.objectweb.jotm.TransactionImpl {} – set date for tx (data=Tue Jun 25 13:54:00 IST 2013, tx=bb14:38:0:0167c3b03eed884b3d…a9ec01:)
    10563 [http-bio-8080-exec-10] DEBUG org.ofbiz.core.entity.TransactionUtil {} – [TransactionUtil.begin] transaction begun
    11324 [http-bio-8080-exec-10] DEBUG com.opensymphony.workflow.spi.jdbc.JDBCWorkflowStore {} – Executing SQL statement: INSERT INTO OS_WFENTRY (ID, NAME, STATE) VALUES (?,?,?)
    11325 [http-bio-8080-exec-10] DEBUG com.opensymphony.workflow.spi.jdbc.JDBCWorkflowStore {} – Executing SQL statement: select count(*) + 1 from OS_WFENTRY
    11410 [http-bio-8080-exec-10] DEBUG com.opensymphony.workflow.AbstractWorkflow {} – theResult=100 Queued
    11410 [http-bio-8080-exec-10] DEBUG com.opensymphony.workflow.AbstractWorkflow {} – Outcome: stepId=100, status=Queued, owner=${caller}, actionId=0, currentStep=0
    11412 [http-bio-8080-exec-10] DEBUG com.opensymphony.workflow.spi.jdbc.JDBCWorkflowStore {} – Executing SQL statement: INSERT INTO OS_CURRENTSTEP (ID,ENTRY_ID, STEP_ID, ACTION_ID, OWNER, START_DATE, DUE_DATE, FINISH_DATE, STATUS, CALLER ) VALUES (?, ?, ?, null, ?, ?, ?, null, ?, null)
    11517 [http-bio-8080-exec-10] DEBUG org.objectweb.jotm.TransactionImpl {} – TransactionImpl.getStatus()
    11518 [http-bio-8080-exec-10] DEBUG org.ofbiz.core.entity.TransactionUtil {} – [TransactionUtil.begin] active transaction in place, so no transaction begun
    11518 [http-bio-8080-exec-10] DEBUG com.opensymphony.workflow.spi.jdbc.JDBCWorkflowStore {} – Executing SQL statement: SELECT NAME, STATE FROM OS_WFENTRY WHERE ID = ?
    11519 [http-bio-8080-exec-10] DEBUG com.opensymphony.workflow.spi.jdbc.JDBCWorkflowStore {} – Executing SQL statement: SELECT NAME, STATE FROM OS_WFENTRY WHERE ID = ?
    11572 [http-bio-8080-exec-10] DEBUG com.opensymphony.workflow.AbstractWorkflow {} – 2 : State is now : 0
    11573 [http-bio-8080-exec-10] DEBUG org.objectweb.jotm.TransactionImpl {} – TransactionImpl.getStatus()
    11573 [http-bio-8080-exec-10] DEBUG org.objectweb.jotm.Current {} – tx=bb14:38:0:0167c3b03eed884b3d…a9ec01:
    11574 [http-bio-8080-exec-10] DEBUG org.objectweb.jotm.TransactionImpl {} – TransactionImpl.commit (tx= bb14:38:0:0167c3b03eed884b3d…a9ec01:)
    11574 [http-bio-8080-exec-10] DEBUG org.objectweb.jotm.TransactionImpl {} – unset timer for tx (timer=org.objectweb.jotm.TimerEvent@698df4bf, tx=bb14:38:0:0167c3b03eed884b3d…a9ec01:)
    11574 [http-bio-8080-exec-10] DEBUG org.objectweb.jotm.TimerEvent {} – TimerEvent(bb14:38:0:0167c3b03eed884b3d…a9ec01:).unset
    11575 [http-bio-8080-exec-10] DEBUG org.objectweb.jotm.Current {} – xid=bb14:38:0:0167c3b03eed884b3d…a9ec01:
    11575 [http-bio-8080-exec-10] DEBUG org.objectweb.jotm.Current {} – threadTx.set = null
    11575 [http-bio-8080-exec-10] DEBUG org.objectweb.jotm.Current {} – remove tx from xid (xid=bb14:38:0:0167c3b03eed884b3d…a9ec01:)
    11576 [http-bio-8080-exec-10] DEBUG org.objectweb.jotm.Current {} – threadTx.set null
    11576 [http-bio-8080-exec-10] DEBUG org.ofbiz.core.entity.TransactionUtil {} – [TransactionUtil.commit] transaction committed
    11576 [http-bio-8080-exec-10] DEBUG com.opensymphony.workflow.spi.jdbc.JDBCWorkflowStore {} – Executing SQL statement: SELECT NAME, STATE FROM OS_WFENTRY WHERE ID = ?
    11578 [http-bio-8080-exec-10] DEBUG com.opensymphony.workflow.spi.jdbc.JDBCWorkflowStore {} – Executing SQL statement: SELECT ID, STEP_ID, ACTION_ID, OWNER, START_DATE, DUE_DATE, FINISH_DATE, STATUS, CALLER FROM OS_CURRENTSTEP WHERE ENTRY_ID = ?
    11579 [http-bio-8080-exec-10] DEBUG com.opensymphony.workflow.spi.jdbc.JDBCWorkflowStore {} – Executing SQL statement: SELECT PREVIOUS_ID FROM OS_CURRENTSTEP_PREV WHERE ID = ?
    11580 [http-bio-8080-exec-10] DEBUG org.objectweb.jotm.Current {} – Current.getStatus(): NO_TRANSACTION
    11580 [http-bio-8080-exec-10] INFO org.ofbiz.core.entity.TransactionUtil {} – [TransactionUtil.commit] Not committing transaction, status is STATUS_NO_TRANSACTION
    11580 [http-bio-8080-exec-10] DEBUG org.objectweb.jotm.Current {} – Current.getStatus(): NO_TRANSACTION
    11581 [http-bio-8080-exec-10] DEBUG org.objectweb.jotm.TransactionImpl {} – xid= bb14:38:0:0167c3b03eed884b3d…b9ec02:
    11581 [http-bio-8080-exec-10] DEBUG org.objectweb.jotm.TransactionImpl {} – timeout= 60
    11581 [http-bio-8080-exec-10] DEBUG org.objectweb.jotm.InternalTransactionContext {} – xid=bb14:38:0:0167c3b03eed884b3d…b9ec02:, timeout=60
    11581 [http-bio-8080-exec-10] DEBUG org.objectweb.jotm.Current {} – new tx=bb14:38:0:0167c3b03eed884b3d…b9ec02:
    11581 [http-bio-8080-exec-10] DEBUG org.objectweb.jotm.TransactionImpl {} – TransactionImpl.doAttach flag= TMJOIN
    11581 [http-bio-8080-exec-10] DEBUG org.objectweb.jotm.TransactionImpl {} – number of enlisted= 0
    11581 [http-bio-8080-exec-10] DEBUG org.objectweb.jotm.Current {} – threadTx set to bb14:38:0:0167c3b03eed884b3d…b9ec02:
    11581 [http-bio-8080-exec-10] DEBUG org.objectweb.jotm.Current {} – Associate tx to xid (xid=bb14:38:0:0167c3b03eed884b3d…b9ec02:) tx =bb14:38:0:0167c3b03eed884b3d…b9ec02:
    11581 [http-bio-8080-exec-10] DEBUG org.objectweb.jotm.TimerEvent {} – TimerEvent.new(bb14:38:0:0167c3b03eed884b3d…b9ec02:,60,null,false)
    11582 [http-bio-8080-exec-10] DEBUG org.objectweb.jotm.TransactionImpl {} – set timer for tx (timer=org.objectweb.jotm.TimerEvent@138bd16f, tx=bb14:38:0:0167c3b03eed884b3d…b9ec02:)
    11582 [http-bio-8080-exec-10] DEBUG org.objectweb.jotm.TransactionImpl {} – set date for tx (data=Tue Jun 25 13:54:01 IST 2013, tx=bb14:38:0:0167c3b03eed884b3d…b9ec02:)
    11582 [http-bio-8080-exec-10] DEBUG org.ofbiz.core.entity.TransactionUtil {} – [TransactionUtil.begin] transaction begun
    11582 [http-bio-8080-exec-10] DEBUG com.opensymphony.workflow.spi.jdbc.JDBCWorkflowStore {} – Executing SQL statement: SELECT NAME, STATE FROM OS_WFENTRY WHERE ID = ?
    11583 [http-bio-8080-exec-10] DEBUG com.opensymphony.workflow.spi.jdbc.JDBCWorkflowStore {} – Executing SQL statement: SELECT ID, STEP_ID, ACTION_ID, OWNER, START_DATE, DUE_DATE, FINISH_DATE, STATUS, CALLER FROM OS_CURRENTSTEP WHERE ENTRY_ID = ?
    11583 [http-bio-8080-exec-10] DEBUG com.opensymphony.workflow.spi.jdbc.JDBCWorkflowStore {} – Executing SQL statement: SELECT PREVIOUS_ID FROM OS_CURRENTSTEP_PREV WHERE ID = ?
    11584 [http-bio-8080-exec-10] DEBUG com.opensymphony.workflow.AbstractWorkflow {} – theResult=200 Queued
    11585 [http-bio-8080-exec-10] DEBUG com.opensymphony.workflow.AbstractWorkflow {} – Outcome: stepId=200, status=Queued, owner=${caller}, actionId=101, currentStep=100
    11585 [http-bio-8080-exec-10] DEBUG com.opensymphony.workflow.spi.jdbc.JDBCWorkflowStore {} – Executing SQL statement: UPDATE OS_CURRENTSTEP SET STATUS = ?, ACTION_ID = ?, FINISH_DATE = ?, CALLER = ? WHERE ID = ?
    11639 [http-bio-8080-exec-10] DEBUG com.opensymphony.workflow.spi.jdbc.JDBCWorkflowStore {} – Executing SQL statement: INSERT INTO OS_HISTORYSTEP (ID,ENTRY_ID, STEP_ID, ACTION_ID, OWNER, START_DATE, FINISH_DATE, STATUS, CALLER) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
    11694 [http-bio-8080-exec-10] DEBUG com.opensymphony.workflow.spi.jdbc.JDBCWorkflowStore {} – Executing SQL statement: DELETE FROM OS_CURRENTSTEP_PREV WHERE ID = ?
    11697 [http-bio-8080-exec-10] DEBUG com.opensymphony.workflow.spi.jdbc.JDBCWorkflowStore {} – Executing SQL statement: DELETE FROM OS_CURRENTSTEP WHERE ID = ?
    11751 [http-bio-8080-exec-10] DEBUG com.opensymphony.workflow.spi.jdbc.JDBCWorkflowStore {} – Executing SQL statement: INSERT INTO OS_CURRENTSTEP (ID,ENTRY_ID, STEP_ID, ACTION_ID, OWNER, START_DATE, DUE_DATE, FINISH_DATE, STATUS, CALLER ) VALUES (?, ?, ?, null, ?, ?, ?, null, ?, null)
    11861 [http-bio-8080-exec-10] DEBUG com.opensymphony.workflow.spi.jdbc.JDBCWorkflowStore {} – Executing SQL statement: INSERT INTO OS_CURRENTSTEP_PREV (ID, PREVIOUS_ID) VALUES (?, ?)
    11917 [http-bio-8080-exec-10] DEBUG com.opensymphony.workflow.spi.jdbc.JDBCWorkflowStore {} – Executing SQL statement: SELECT NAME, STATE FROM OS_WFENTRY WHERE ID = ?
    11918 [http-bio-8080-exec-10] DEBUG com.opensymphony.workflow.spi.jdbc.JDBCWorkflowStore {} – Executing SQL statement: SELECT ID, STEP_ID, ACTION_ID, OWNER, START_DATE, DUE_DATE, FINISH_DATE, STATUS, CALLER FROM OS_CURRENTSTEP WHERE ENTRY_ID = ?
    11918 [http-bio-8080-exec-10] DEBUG com.opensymphony.workflow.spi.jdbc.JDBCWorkflowStore {} – Executing SQL statement: SELECT PREVIOUS_ID FROM OS_CURRENTSTEP_PREV WHERE ID = ?
    11919 [http-bio-8080-exec-10] DEBUG com.opensymphony.workflow.spi.jdbc.JDBCWorkflowStore {} – Executing SQL statement: SELECT NAME, STATE FROM OS_WFENTRY WHERE ID = ?
    11920 [http-bio-8080-exec-10] DEBUG com.opensymphony.workflow.spi.jdbc.JDBCWorkflowStore {} – Executing SQL statement: SELECT ID, STEP_ID, ACTION_ID, OWNER, START_DATE, DUE_DATE, FINISH_DATE, STATUS, CALLER FROM OS_CURRENTSTEP WHERE ENTRY_ID = ?
    11920 [http-bio-8080-exec-10] DEBUG com.opensymphony.workflow.spi.jdbc.JDBCWorkflowStore {} – Executing SQL statement: SELECT PREVIOUS_ID FROM OS_CURRENTSTEP_PREV WHERE ID = ?
    11921 [http-bio-8080-exec-10] DEBUG org.objectweb.jotm.TransactionImpl {} – TransactionImpl.getStatus()
    11921 [http-bio-8080-exec-10] DEBUG org.objectweb.jotm.Current {} – tx=bb14:38:0:0167c3b03eed884b3d…b9ec02:
    11921 [http-bio-8080-exec-10] DEBUG org.objectweb.jotm.TransactionImpl {} – TransactionImpl.commit (tx= bb14:38:0:0167c3b03eed884b3d…b9ec02:)
    11921 [http-bio-8080-exec-10] DEBUG org.objectweb.jotm.TransactionImpl {} – unset timer for tx (timer=org.objectweb.jotm.TimerEvent@138bd16f, tx=bb14:38:0:0167c3b03eed884b3d…b9ec02:)
    11921 [http-bio-8080-exec-10] DEBUG org.objectweb.jotm.TimerEvent {} – TimerEvent(bb14:38:0:0167c3b03eed884b3d…b9ec02:).unset
    11921 [http-bio-8080-exec-10] DEBUG org.objectweb.jotm.Current {} – xid=bb14:38:0:0167c3b03eed884b3d…b9ec02:
    11921 [http-bio-8080-exec-10] DEBUG org.objectweb.jotm.Current {} – threadTx.set = null
    11922 [http-bio-8080-exec-10] DEBUG org.objectweb.jotm.Current {} – remove tx from xid (xid=bb14:38:0:0167c3b03eed884b3d…b9ec02:)
    11922 [http-bio-8080-exec-10] DEBUG org.objectweb.jotm.Current {} – threadTx.set null
    11922 [http-bio-8080-exec-10] DEBUG org.ofbiz.core.entity.TransactionUtil {} – [TransactionUtil.commit] transaction committed
    11922 [http-bio-8080-exec-10] DEBUG com.fhl.ClientInformationPage$1 {} – check2

    As i see above it shows me that “JOTM Recovery is disabled” so how to enable it or is their something else which i am missing..?

  9. grails jndi says:

    I like to have many options in configuring the JNDI datasource. Similar to how C3p0 is configured.

  10. Keith Crowe says:

    Thanks, Very useful for configuration going to try to post example of session factory configuration as well

    org.hibernate.dialect.MySQLDialect
    true
    org.hibernate.transaction.JTATransactionFactory
    java:comp/UserTransaction
    org.hibernate.transaction.JOTMTransactionManagerLookup
    true
    true
    jta

    ormappings/com/dogtown/domain/tournament/Tournament.hbm.xml
    ormappings/com/dogtown/domain/day/Day.hbm.xml
    ormappings/com/dogtown/domain/scorecard/Scorecard.hbm.xml
    ormappings/com/dogtown/domain/skin/Skins.hbm.xml
    ormappings/com/dogtown/domain/flight/Flight.hbm.xml
    ormappings/com/dogtown/domain/player/Player.hbm.xml
    queries/PlayerDAO_queries.hbm.xml
    queries/TournamentDAO_queries.hbm.xml
    queries/FlightDAO_queries.hbm.xml
    queries/ScorecardDAO_queries.hbm.xml
    queries/DayDAO_queries.hbm.xml
    queries/SkinDAO_queries.hbm.xml

  11. Keith Crowe says:
        <jee:jndi-lookup id="dataSource" jndi-name="java:comp/env/jdbc/mysql" resource-ref="true"/>
        
         <tx:jta-transaction-manager type="userTransaction"/>
    
    <!-- Hibernate session factory -->
    <bean id="sessionFactory" 
        class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
     
        <property name="dataSource">
          <ref bean="dataSource"/>
        </property>
     
        <property name="hibernateProperties">
           <props>
             <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
             <prop key="hibernate.show_sql">true</prop>
             <prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</prop>
             <prop key="jta.UserTransaction">java:comp/UserTransaction</prop>        
    		 <prop key="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JOTMTransactionManagerLookup</prop>                
    		 <prop key="hibernate.transaction.flush_before_completion">true</prop>
             <prop key="hibernate.transaction.auto_close_session">true</prop>
             <prop key="hibernate.current_session_context_class">jta</prop>
           </props>
        </property>
     
        <property name="mappingResources">
    		<list>
              <value>ormappings/com/dogtown/domain/tournament/Tournament.hbm.xml</value>
              <value>ormappings/com/dogtown/domain/day/Day.hbm.xml</value>
              <value>ormappings/com/dogtown/domain/scorecard/Scorecard.hbm.xml</value>
              <value>ormappings/com/dogtown/domain/skin/Skins.hbm.xml</value>
              <value>ormappings/com/dogtown/domain/flight/Flight.hbm.xml</value>
              <value>ormappings/com/dogtown/domain/player/Player.hbm.xml</value>
              <value>queries/PlayerDAO_queries.hbm.xml</value>
              <value>queries/TournamentDAO_queries.hbm.xml</value>
              <value>queries/FlightDAO_queries.hbm.xml</value>
              <value>queries/ScorecardDAO_queries.hbm.xml</value>
              <value>queries/DayDAO_queries.hbm.xml</value>
              <value>queries/SkinDAO_queries.hbm.xml</value>
    		</list>
        </property>	
     
    </bean>
    
    <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
        <property name="transactionSynchronizationRegistryName" value="java:comp/env/TransactionSynchronizationRegistry"/>
        <property name="transactionManagerName" value="java:comp/UserTransaction"/>
    </bean>
    
  12. Thanks, nice post

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: