views:

295

answers:

2

As shown below, I am accessing a Service layer method inside of another DAO. (Every DAO in the system is implemented using HibernateDAOSupport class)

I wanted to rollback the transaction when #1 or #2 (commented in the following code) is failed. But when #2 throws an exception, #1 does not get rolled back and I can see the entries in the database.

@Transactional(readOnly=false, rollbackFor={DuplicateEmailException.class,DuplicateLoginIdException.class,IdentityException.class},propagation=Propagation.REQUIRES_NEW)
    public void createUserProfile(UserProfile profile)
      throws DuplicateEmailException, DuplicateLoginIdException,
      IdentityException {

     // #1 create principal using Identity Service
     identityService.createPrincipal(profile.getSecurityPrincipal());

     try {
     // #2 save user profile using Hibernate Template
      getHibernateTemplate().save(profile);
     } catch (RuntimeException e) {
      throw new IdentityException("UseProfile create Error", e);
     }

}

Here is the signature for createPrincipal() method of'IdentityService'.

public void createPrincipal(Principal principal) throws DuplicateEmailException,DuplicateLoginIdException,IdentityException ;

There's no Transaction management configured in 'IdentityService'

What I am doing wrong here ?

A: 

During the calls identityService.createPrincipal(profile.getSecurityPrincipal()); aren't you flushing the session ? (executing a query for example, with FlushMode.AUTO)

Horia Chiorean
A: 

Try Propagation.REQUIRED, instead of Propagation.REQUIRES_NEW

Bozho