Announcement Announcement Module
Collapse
No announcement yet.
Problems with transaction rollback Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problems with transaction rollback

    Hi all, I'm having a problem with transaction rollback.
    It's does not rollback after a unchecked exception that is declared in the TransactionProxyFactoryBean configuration. Let's see some piece of code:

    the config xml:
    Code:
    <bean id="userServiceTarget" class="com.integrareti.integraframework.service.UserAccountServiceImpl"
    		singleton="true" autowire="byType" />
    
    
    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager" lazy-init="default" autowire="byType" dependency-check="default" />
    
    <bean id="userService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
    lazy-init="default" autowire="default" dependency-check="default">
    				
    <property name="transactionManager">
          <ref local="transactionManager" />
    	   </property>
    		<property name="target">
    			<ref local="userServiceTarget" />
    		</property>
    		<property name="transactionAttributes">
    			<props>
    				<prop key="save*">
    					PROPAGATION_REQUIRED, -AppsForYourDomainException
    				</prop>
    				<prop key="delete*">PROPAGATION_REQUIRED</prop>
    				<prop key="get*">PROPAGATION_REQUIRED</prop>
    				<prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
    			</props>
    		</property>
    	</bean>
    the service:
    Code:
    public class UserAccountServiceImpl extends ServiceInterfaceImpl implements
    		ServiceInterface {
    
    @Override
    public Person save(Object person) {
    		User user = null;
    		if (person instanceof User) {
    			user = (User) person;
    			try {
    				getAppsClient().createUser(user.getGoogleAccount(),
    						user.getGivenName(), user.getFamilyName(),
    						user.getPassword());
    			} catch (AppsForYourDomainException e) {
    				System.out.println(e.getErrorCode());
    				e.printStackTrace();
    			} catch (ServiceException e) {
    				e.printStackTrace();
    			} catch (IOException e) {
    				e.printStackTrace();
    			}
    		}
    		super.save(person);
    		return user;
    	}
    }
    unit test:

    Code:
    	public void testSaveAccount() {
    		User u = new User();
    		u.setGivenName("name");
    		u.setFamilyName("family");
    		u.setGoogleAccount("[email protected]");
    		u.setPassword("123");
    		u.setUsername("foo");
    		userService.save(u);
    	}
    When I execute this test I get an AppsForYourDomainException, but the transaction isn't rollback-ed, why? Is it because of the call to the super.save()?

    Thanks in advance!

  • #2
    Although you've setup the configuration to roll back on the exception, you don't actually throw it from the service, hence the transaction proxy doesn't know about it and the transaction isn't rolled back.
    http://www.springframework.org/docs/...decl-explained
    Last edited by karldmoore; Aug 27th, 2007, 03:14 PM.

    Comment


    • #3
      Originally posted by karldmoore View Post
      Although you've setup the configuration to roll back on the exception, you don't actually throw it from the service, hence the transaction proxy doesn't know about it and the transaction isn't rolled back.
      http://www.springframework.org/docs/...decl-explained
      Thanks for the response!

      I've found out what I was missing: getAppsClient().createUser() is not part of this service!

      Comment


      • #4
        Originally posted by tagama View Post
        I've found out what I was missing: getAppsClient().createUser() is not part of this service!
        Not quite sure I follow, but as long as you've got it working that's the main thing .
        Last edited by karldmoore; Aug 27th, 2007, 03:14 PM.

        Comment

        Working...
        X