1

I'm using spring, oracle and jotm (in tomcat) to use 2PC commit. Below is the spring configuration.

<aop:config>
    <aop:pointcut id="defaultOperation"
        expression="execution(* jatis.avantrade.foundation.model.engine.*.*(..))" />
    <aop:advisor advice-ref="defaultTrxAdvice" pointcut-ref="defaultOperation" />
</aop:config>

<tx:advice id="defaultTrxAdvice" transaction-manager="trxManager">
    <tx:attributes>
        <tx:method name="check*" read-only="true" />
        <tx:method name="get*" read-only="true" />
        <tx:method name="is*" read-only="true" />
        <tx:method name="load*" read-only="true" />
        <tx:method name="select*" read-only="true" />
        <tx:method name="count*" read-only="true" />
        <tx:method name="search*" read-only="true" />
        <tx:method name="list*" read-only="true" />
        <tx:method name="*" rollback-for="Throwable" />
    </tx:attributes>
</tx:advice>

<bean id="txImpl" class="org.springframework.transaction.jta.JotmFactoryBean" />




<bean id="trxManager"
    class="org.springframework.transaction.jta.JtaTransactionManager">
    <property name="transactionManager" ref="txImpl" />
    <property name="userTransaction" ref="txImpl" />
</bean>

The questions is when I call getTransactionManager().getTransaction() using JOTM object, it returns null.

Current cur = (Current) ContextHelper.getApplicationContext()
                    .getBean("txImpl");
            try {
                log.error("cur : " cur.getTransactionManager().getTransaction());
        } catch (SystemException e) {
            log.error(e.getMessage(), e);
        }

How can I fix this issue?

Iswanto San
  • 18,263
  • 13
  • 58
  • 79

1 Answers1

1

One approach might be to use Apache TomEE which is Tomcat with the TransactionManager already integrated. The write a simple Spring factory bean to hand Spring the TransactionManager and UserTransaction.

Both can be looked up from JNDI:

  • java:comp/TransactionManager
  • java:comp/UserTransaction

That factory would just replace the one from the above config:

<bean id="txImpl" class="org.foo.MyTransactionFactoryBean" />

Though, it's very likely Spring already has a factory bean for looking up the TransactionManager via these names.

David Blevins
  • 19,178
  • 3
  • 53
  • 68