Results 1 to 2 of 2

Thread: Spring Declarative Transaction Management- Rollback not happening

  1. #1

    Default Spring Declarative Transaction Management- Rollback not happening

    Hello ,

    I am trying spring trnasaction management for my code. I am using spring jdbc and I call mmutiple insert /update in one method. I want to wrap this method inside transaction support so that commit/rollback should happen in whole.

    To test I am throwing an exception but I see that no rollback is happening . Please suggest what is going wrong in configuration.

    Here is my spring configuration file
    Code:
    	<!-- this is the service object that we want to make transactional -->
      	<bean id="ReactantResourceService" class="com.X.X.ReactantResource"/>
      
    	<tx:annotation-driven transaction-manager="txManager" />
    
    	<bean id="txManager"
    		class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    		<property name="dataSource" ref="reactantDataSource" />
    	</bean>
    Here is my source code
    Code:
    package com.X.X;
    
    import org.springframework.transaction.annotation.Transactional;
    import org.springframework.transaction.support.TransactionSynchronizationManager;
    
    
    @Path("/test")
    @Transactional(readOnly = true)
    public class ReactantResource {
    
    	
    	//other code
    	@POST
    	@Path("")
    	@Consumes("multipart/form-data")
    	@Produces("application/xml")
    	@Transactional(propagation=Propagation.REQUIRED, readOnly=false,rollbackFor = Exception.class)
    	public List<Reactant> createandUpdate (
    			@HeaderParam(SGCConstants.req_UserIDKey) String userID,
    			MultipartFormDataInput input)
    			throws SGCExceptions, IOException {
    		assert TransactionSynchronizationManager.isActualTransactionActive();
    		//other create/update code
    
    		reactantList = create(reactantClass, inputSD);
    		rcDAO.update(reactantClass,reactantList.size());
    		if(true)
    			throw new IOException("testing txn");
    		return reactantList;
    	}
    
    }
    My method is executing successfully and create and update methods are executing successfully and even after throwing exception the data is not rolled back.

    Is there any misconfiguration ?

  2. #2

    Default

    Hi,

    before going further, I suggest you to try what's described here.

    Best,
    Carlos.

Posting Permissions

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