-->
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: Using Spring AOP based transaction with Struts1.x
PostPosted: Tue Aug 07, 2012 11:25 am 
Newbie

Joined: Tue Aug 07, 2012 11:19 am
Posts: 1
Hi Friends,

I am developing one application using Struts1.3+Spring2.5+Hibernate3.6 to do practice.
In this application I am using Spring AOP transactions, but transaction is not working for me.

Please check my code snippets and help me.

web.xml
=======
in addition to general entries, I have added the following code as well

Code:
<context-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>/WEB-INF/applicationContext.xml</param-value>
   </context-param>
   
    <listener>
     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
   </listener>


applicationContext.xml
==================

Code:
<bean id="transactionManager"
      class="org.springframework.orm.hibernate3.HibernateTransactionManager">
      <property name="sessionFactory" ref="mySessionFactory" />
   </bean>
   
   <bean id="matchAllWithSave"
        class="org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource" lazy-init='true'>
         <property name="properties">
            <props>
               <prop key="save*">
                  PROPAGATION_REQUIRED,-Exception</prop>
               <prop key="start*">
                  PROPAGATION_REQUIRED,-Exception</prop>
               <prop key="newTx*">
                  PROPAGATION_REQUIRES_NEW,-Exception</prop>                  
               <prop key="*">PROPAGATION_SUPPORTS,readOnly</prop>
            </props>
         </property>
         </bean>   
    <bean id="hibernateInterceptor" class="org.springframework.orm.hibernate3.HibernateInterceptor">
      <property name="sessionFactory" ref="mySessionFactory" />
   </bean>         
   <bean id="matchSaveTxInterceptor"
        class="org.springframework.transaction.interceptor.TransactionInterceptor" lazy-init="true">
      <property name="transactionManager"><ref bean="transactionManager"/></property>
      <property name="transactionAttributeSource"><ref bean="matchAllWithSave"/></property>
      
   </bean>
   <bean id="autoProxyCreator"
        class="com.mokjas.extra.InterfaceAutoProxyCreator" lazy-init="true">
      <property name="interceptorNames">
        <list>
         <idref local="matchSaveTxInterceptor"/>
         <idref local="hibernateInterceptor"/>
         
        </list>
      </property>
      <property name="interfaces">
        <list>
         <value>com.mokjas.service.ITransactionalSaveService</value>
        </list>
      </property>
   </bean>


Here all my service classes implemented this "ITransactionalSaveService" marker interface. So as per the above configuration,any service class which has save* method should wrap with transactions. But for me it is not working.

ServiceFinder.java
==============
Code:
public class ServiceFinder {
   public static ApplicationContext getContext(HttpServletRequest httpRequest) {
      return WebApplicationContextUtils.getRequiredWebApplicationContext(
            httpRequest.getSession().getServletContext());
   }
}

Struts Action class:
==============
here in my action class I am calling save* method of my service class(implemented ITransactionalSaveService)

Code:
transferService.saveAccountTransfer(fromBean, toBean);


ServiceImpl class:
==============

Code:
public void saveAccountTransfer(UserBean fromBean,UserBean toBean){
      // TODO Auto-generated method stub
      
      getBankDAO().processTransfer(toBean,"To");
      getBankDAO().processTransfer(fromBean,"From");
      
   }


DAO Impl class:
===========
Code:
public void processTransfer(UserBean bean, String name) {
      Session session=getSessionFactory().openSession();
      session.saveOrUpdate(bean);
      session.close();   
      
   }


After we execute this
Code:
session.saveOrUpdate(bean);

my hibernate is not saving the beans accordingly because there is no transaction applied. so hibernate is generating only select statement,not update statement.

Please help me to solve my issue.

Thanks,
Bunny


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.