2009-10-28 65 views
1

如下所示,我正在访问另一个DAO中的Service层方法。 (系统中的每个DAO都使用HibernateDAOSupport类实现)几个DAO层之间的交易?

我想在#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”配置

我在做什么错在这里没有事务管理?

+0

的identityService.createPrincipal(...)方法必须创建它自己的事务。它的DAO如何配置? – 2009-10-28 03:16:34

+0

DAO尚未配置任何事务(无事务性注释)。 – 2009-10-28 03:20:24

+0

只有我使用'Transactional'注释的地方在上面的DAO中。 – 2009-10-28 03:21:57

回答

0

在通话期间identityService.createPrincipal(profile.getSecurityPrincipal());是不是在冲洗会话? (执行例如查询,与FlushMode.AUTO)

1

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