我们有3个EJB来处理我们的业务,如下所示:
@Stateless
public class BeanA {
@PersistenceContext(unitName = "primary")
private EntityManager em;
@EJB private BeanB beanB;
public void handle() {
EntityA entity= new EntityA();
....
beanB.handle();
em.persist(entity); //Transaction does not rollback and saved entity
}
}
@Stateless
public class BeanB {
@EJB private BeanC beanC;
public void handle() {
beanC.handle();
}
}
@Stateless
public class BeanC {
public void handle() {
try {
throw new RunTimeException("error occurred!!");
} catch(RunTimeException e) {
e.printStacktrace();
}
}
}
根据JTA的概念,如果发生RuntimeExcpetion,则当前事务将被回滚,我希望上述事务应被回滚,但不回滚。我们还将Wildfly10用作应用程序服务器,并在数据源中使用活动的JTA =“ true”选项。
关于这个问题有什么想法吗?
答案 0 :(得分:0)
您需要从EJB抛出异常,而又不能将其捕获。将BeanC更改为以下实现。
@Stateless
public class BeanC {
public void handle() {
throw new RuntimeException("error occurred!!");
}
}