-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: JTA Tx issue with Spring+Hibernate in websphere
PostPosted: Wed Jun 25, 2008 7:27 pm 
Newbie

Joined: Wed Jun 25, 2008 7:14 pm
Posts: 1
Gurus,
I came across couple of threads regarding this issue in this forum but nothing really was helpfull.
I am sure there are many people out there who already implemented this. So please help me and others who are stuggling with this.
Thank you in advance.

Iam using WAS 6.1.0.13, spring 2.5 and Hibernate 3.2.6 GA
The problem is the transaction is not rolling back.
If I try to use CMT with following configuration
Code:
<prop key="hibernate.transaction.factory_class">org.hibernate.transaction.CMTTransactionFactory</prop>

then I get "The chosen transaction strategy requires access to the JTA TransactionManager" error.

Here is the configuration

Code:
<bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate">
   <constructor-arg type="java.util.Properties">
      <props>
         <prop key="java.naming.factory.initial">com.ibm.websphere.naming.WsnInitialContextFactory</prop>
         <prop key="java.naming.provider.url">iiop://localhost:2810</prop>
      </props>
   </constructor-arg>
</bean>

<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
   <property name="jndiTemplate" ref="jndiTemplate" />
   <property name="jndiName" value="jdbc/myDatasource"/>
   <property name="lookupOnStartup" value="false"/>
   <property name="cache" value="true"/>   
   <property name="proxyInterface" value="javax.sql.DataSource"/>
</bean>


Code:
<bean id="transactionManager" class="org.springframework.transaction.jta.WebSphereUowTransactionManager"/>
<tx:advice id="serviceTransactionAdvice" transaction-manager="transactionManager">
   <tx:attributes>
      <tx:method name="get*"     read-only="true" propagation="SUPPORTS" isolation="REPEATABLE_READ"/>
      <tx:method name="find*"    read-only="true" propagation="SUPPORTS" isolation="REPEATABLE_READ"/>
      <tx:method name="update*"  read-only="false" propagation="REQUIRED" isolation="REPEATABLE_READ" rollback-for="BaseException" />
      <tx:method name="delete*"  read-only="false" propagation="REQUIRED" isolation="REPEATABLE_READ" rollback-for="BaseException" />
      <tx:method name="save*"    read-only="false" propagation="REQUIRED" isolation="REPEATABLE_READ" rollback-for="BaseException" />
   </tx:attributes>
</tx:advice>
      
<aop:config>
   <aop:pointcut id="userMaintainence" expression="execution(* com.src.service.UserMaintainenceService.*(..))" />
   <aop:advisor advice-ref="serviceTransactionAdvice" pointcut-ref="userMaintainence" />
</aop:config>



Code:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
   <property name="lobHandler" ref="oracleLobHandler" />
   <property name="dataSource" ref="dataSource" />
   <property name="mappingResources">
      <list>
         <value>user.hbm.xml</value>
         ..............       
      </list>
      </property>
   <property name="hibernateProperties">
      <props>
         <prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</prop>           
         <prop key="hibernate.transaction.manager_lookup">org.hibernate.transaction.WebSphereExtendedJTATransactionLookup</prop>
         <prop key="jta.UserTransaction">java:comp/UserTransaction</prop>

         <prop key="hibernate.connection.autocommit">false</prop>

         <prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop>
         
         <prop key="hibernate.transaction.flush_before_completion">true</prop>
         <prop key="hibernate.transaction.auto_close_session">true</prop>
         <prop key="hibernate.connection.release_mode">auto</prop>
         <prop key="hibernate.order_updates">true</prop>
         
         <prop key="hibernate.show_sql">true</prop>
         <prop key="hibernate.cglib.use_reflection_optimizer">true</prop>
         <prop key="hibernate.generate_statistics">true</prop>
         <prop key="hibernate.cache.provider_class">org.hibernate.cache.TreeCacheProvider</prop>
         <prop key="hibernate.cache.use_second_level_cache">true</prop>
         <prop key="hibernate.cache.use_query_cache">true</prop>
         <prop key="hibernate.cache.use_minimal_puts">true</prop>
         <prop key="hibernate.jdbc.batch_size">30</prop>

      </props>
   </property>
</bean>

<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate"
p:sessionFactory-ref="sessionFactory" />


Here is the service interface and class

Code:
public interface UserMaintainenceService {

   void saveUser(User user)throws BaseException;

}

public class UserMaintainenceServiceImpl implements UserMaintainenceService {
   protected UserMaintainenceDao userMaintainenceDao;
   public void saveUser(User user)throws BaseException {
      try{
         userMaintainenceDao.saveUser(user);
         //Now I want to rollback here
         if(user.getUserLoginId().length()<6){
            throw new BaseException("Can not add this user!");
         }
      } catch (DataAccessException e) {
         throw new BaseException(e.getMessage());
      }
   }

}


Here is the log

Code:
INFO  Message: Exec:saveUser()
DEBUG Message: Creating new transaction with name [null]: PROPAGATION_SUPPORTS,ISOLATION_REPEATABLE_READ,readOnly
DEBUG Message: Invoking WebSphere UOW action: type=1, join=true
DEBUG Message: Initializing transaction synchronization
DEBUG Message: Bound value [org.springframework.orm.hibernate3.SessionHolder@69a269a2] for key [org.hibernate.impl.SessionFactoryImpl@33683368] to thread [WebContainer : 1]
DEBUG Message: Retrieved value [org.springframework.orm.hibernate3.SessionHolder@69a269a2] for key [org.hibernate.impl.SessionFactoryImpl@33683368] bound to thread [WebContainer : 1]
DEBUG Message: Retrieved value [org.springframework.orm.hibernate3.SessionHolder@69a269a2] for key [org.hibernate.impl.SessionFactoryImpl@33683368] bound to thread [WebContainer : 1]
DEBUG Message: Triggering beforeCommit synchronization
DEBUG Message: Triggering beforeCompletion synchronization
DEBUG Message: Removed value [org.springframework.orm.hibernate3.SessionHolder@69a269a2] for key [org.hibernate.impl.SessionFactoryImpl@33683368] from thread [WebContainer : 1]
DEBUG Message: Clearing transaction synchronization
DEBUG Message: Returned from WebSphere UOW action: type=1, join=true
DEBUG Message: Creating new transaction with name [null]: PROPAGATION_REQUIRED,ISOLATION_REPEATABLE_READ,-BaseException
DEBUG Message: Invoking WebSphere UOW action: type=1, join=true
DEBUG Message: Initializing transaction synchronization
DEBUG Message: Bound value [org.springframework.orm.hibernate3.SessionHolder@2c8c2c8c] for key [org.hibernate.impl.SessionFactoryImpl@33683368] to thread [WebContainer : 1]
DEBUG Message: Retrieved value [org.springframework.orm.hibernate3.SessionHolder@2c8c2c8c] for key [org.hibernate.impl.SessionFactoryImpl@33683368] bound to thread [WebContainer : 1]
DEBUG Message: Triggering beforeCommit synchronization
DEBUG Message: Triggering beforeCompletion synchronization
DEBUG Message: Removed value [org.springframework.orm.hibernate3.SessionHolder@2c8c2c8c] for key [org.hibernate.impl.SessionFactoryImpl@33683368] from thread [WebContainer : 1]
DEBUG Message: Clearing transaction synchronization
DEBUG Message: Returned from WebSphere UOW action: type=1, join=true


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.