Results 1 to 3 of 3

Thread: Not Rollback - Using <aop:config>

Hybrid View

  1. #1
    Join Date
    Sep 2011
    Posts
    8

    Default Not Rollback - Using <aop:config>



    Hi Friends,

    I am Using Spring AOP. But Roll-backing is not properly working. I am getting bean from Application Context not from Bean Factory and the DataBase is Oracle .

    Here is the Code

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	   xmlns:aop="http://www.springframework.org/schema/aop"
    	   xmlns:tx="http://www.springframework.org/schema/tx"
    	   xsi:schemaLocation="
    	   						http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
    							http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
    							http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
    
    
    
    
    	<bean id="ContactBo"
    		class="com.ct.contacts.bo.impl.ContactsBoImpl">
    		<property name="contactsDao" ref="contactsDao" />
    		<property name="securityDao" ref="TestDao" />
    
    	</bean>
    	
    	<bean id="contactsDao"
    		class="com.ct.contacts.dao.impl.ContactsDaoImpl">
    		<property name="sessionFactory" ref="sessionFactory"></property>
    	</bean>
    
    
    
    
      <tx:advice id="txAdvice" transaction-manager="transactionManager">
        <!-- the transactional semantics... -->
        <tx:attributes>
          <tx:method name="insert*" propagation="REQUIRED"/>
          <!-- other methods use the default transaction settings (see below) -->
          <tx:method name="*"/>
        </tx:attributes>
      </tx:advice>
      
      <aop:config>
        <aop:pointcut id="TestTransactionMethods" expression="execution(* com.ct.contacts.bo.impl.ContactsBoImpl.insert(..))"/>
        <aop:advisor advice-ref="txAdvice" pointcut-ref="TestTransactionMethods"/>
      </aop:config>
    	
    
    </beans>
    
    ------------- Business Class----------------------
    
    
    package com.ct.contacts.bo.impl;
    
    import org.springframework.orm.hibernate3.HibernateTransactionManager;
    
    import com.ct.common.MainDto;
    import com.ct.contacts.dao.ContactsDaoIntf;
    import com.ct.security.dao.TestDaoIntf;
    
    public class ContactsBoImpl implements ContactsBoIntf{
    
    	ContactsDaoIntf contactsDao;
    	TestDaoIntf securityDao;
    	
    	
    	public void setSecurityDao(TestDaoIntf securityDao) {
    		System.out.println("in securityyyy");
    		this.securityDao = securityDao;
    	}
    	
    	
    
    	public void setContactsDao(ContactsDaoIntf contactsDao) {
    		System.out.println("in setterrrrrrrrrrrrrr");
    		this.contactsDao = contactsDao;
    	}
    
    
    
    	public void insert(MainDto objMainDto){
    		try{
    			System.out.println("in ContactsBoImpl");
    		
    				contactsDao.insert(objMainDto.getObjContactsDto());
    	
    				objMainDto.getObjSecurityDto()=null;
    
    				securityDao.insert(objMainDto.getObjSecurityDto());---------------Creating Null value
    				
    		
    		 
    		}catch (Exception ex){
    			System.out.println("EXCEPTION FOUND --------------------");
    			ex.printStackTrace();
    		}
    		
    		}
    
    	
    
    
    }
    The value will be save to First table. It is not rollbacked.

    Kindly give me a solution,

    Aby

  2. #2
    Join Date
    May 2011
    Location
    New Delhi, India
    Posts
    157

    Default

    You are catching the exception in your method. Remove try/catch block. Also the exception being thrown should be of type RuntimeException for the transaction to be rolled back.

    Also you are using old version of Spring. In case you are trying somthing i will suggest using Spring 3.0.

  3. #3
    Join Date
    Sep 2011
    Posts
    8

    Default

    thank you rishishehrawat. Thank you very much

    Aby

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •