【发布时间】:2012-12-10 08:33:23
【问题描述】:
我想不在 EJB 内部而是在 JSF 托管 bean 内部回滚事务。在 EJB 中,我们可以使用 SessionContext.setRollBackOnly(),但我可以在托管 bean 中使用什么?
@Stateless
@Local(AccountLocal.class)
public class AccountBean implements AccountLocal {
public void test1() throws CustomException(){
...
}
public void test2() throws CustomException(){
...
throw new CustomException();
}
public void test3() throws CustomException(){
...
}
public void all() throws CustomException(){
test1();
test2();
test3();
}
}
在我的托管 bean 中:
@SessionScoped
public class LoginBean implements Serializable{
public void test(){
try{
accountBean.test1();
accountBean.test2();
accountBean.test3();
}catch(CustomException e){
// WHAT HERE TO ROLLBACK TRANSACTION ?
}
}
}
编辑:如何确保如果test1、test2 或test3 之一回滚,其他人也会回滚?
我测试了这段代码,即使accountBean.test2(); 回滚,accountBean.test1(); 也会得到验证。
解决方案是否只能将这 3 个方法嵌套在一个 EJB 方法中?
@SessionScoped
public class LoginBean implements Serializable{
public void test(){
try{
accountBean.all();
}catch(CustomException e){
...
}
}
}
【问题讨论】:
标签: jsf transactions ejb