springhibernatetransactionswebspheretransactionmanager

WebSphereUowTransactionManager returning null transactionManager


I have a legacy code that use the TransactionManager to obtain access to the transaction to associate synchronization objects to the transaction afterCommit.

When I migrate to Spring 3, the recommended transaction manager to my solution is WebSphereUowTransactionManager, in truth, I feel that it is only a factory to the real Transaction Manager. But this transaction manager always return null in the method getTransactionManager().

I'm using EJB's 2.1 (legacy, remember?) with CMT.

My configuration is Spring 3.1.2.RELEASE, Hibernate 3.6.8.Final, Websphere 6.1.0.43, my beans are:

<bean 
    id="transactionManager" 
    class="org.springframework.transaction.jta.WebSphereUowTransactionManager" />   


<bean 
    name="auditContextManager" 
    class="... my class ...">
    <property name="transactionManager">
        <bean factory-bean="transactionManager" factory-method="getTransactionManager" />
    </property>
</bean>

My hibernate configuration is:

<hibernate-configuration>
  <session-factory>
    <property name="hibernate.jdbc.fetch_size">200</property>
    <property name="hibernate.jdbc.use_get_generated_keys">true</property>
    <property name="hibernate.bytecode.use_reflection_optimizer">true</property>
    <property name="hibernate.connection.datasource">java:comp/env/jdbc/ORDS</property>
    <property name="hibernate.dialect">org.hibernate.dialect.Oracle9iDialect</property>
    <property name="hibernate.max_fetch_depth">3</property>
    <property name="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</property>
    <property name="hibernate.transaction.factory_class">org.hibernate.transaction.CMTTransactionFactory</property>
    <property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.WebSphereExtendedJTATransactionLookup</property>
    <property name="hibernate.show_sql">false</property>
    ... too much mappings to show here ...
  </session-factory>
</hibernate-configuration>

And my bean auditContextManager has always transactionManager set to null.

It seems to me that WebSphereUowTransactionManager do not expose Transaction Manager intentionally. Is this alright ?

There is any way so I can get the Transaction Manager ? Since WebSphereUowTransactionManager is not really the transaction manager, but only a transaction manager factory.


Solution

  • It is not a factory for the TransactionManager but, as the name suggest, the UOWManager. It uses the Websphere native API for managing transactions (which has broader support for certain things than the plain JTA api).

    So there isn't going to be a TransactionManager it will always be null.

    Basically if you want the transactionamanager you will have to do a JNDI lookup.