开发者

Transaction between several DAO layers?

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 ?


Try Propagation.REQUIRED, instead of Propagation.REQUIRES_NEW


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜