如下所示,我正在訪問另一個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」配置
我在做什麼錯在這裏沒有事務管理?
的identityService.createPrincipal(...)方法必須創建它自己的事務。它的DAO如何配置? – 2009-10-28 03:16:34
DAO尚未配置任何事務(無事務性註釋)。 – 2009-10-28 03:20:24
只有我使用'Transactional'註釋的地方在上面的DAO中。 – 2009-10-28 03:21:57