1

如下所示,我正在访问另一个 DAO 内部的服务层方法。(系统中的每一个DAO都是使用HibernateDAOSupport类实现的)

我想在#1 或#2(在下面的代码中注释)失败时回滚事务。但是当#2 抛出异常时,#1 不会回滚,我可以看到数据库中的条目。

@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);
        }

}

这是“IdentityService”的 createPrincipal() 方法的签名。

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

“IdentityService”中没有配置事务管理

我在这里做错了什么?

4

2 回答 2

1

尝试Propagation.REQUIRED,而不是Propagation.REQUIRES_NEW

于 2009-11-25T09:10:33.983 回答
0

在通话期间,identityService.createPrincipal(profile.getSecurityPrincipal());您不是在刷新会话吗?(例如,使用 FlushMode.AUTO 执行查询)

于 2009-11-09T10:56:20.973 回答