我有一个无死会话bean,其方法如下:
public void process(){
try {
// function which inserts some data
Properties properties = new Properties();
InitialContext ic = new InitialContext(properties);
CouponBatchSessionBeanRemote CBSBR = (CouponBatchSessionBeanRemote) ic.lookup(CouponBatchSessionBeanRemote.class.getName());
CBSBR.createCouponBatchFromPlantAppFile(batch);
} catch (Exception e1) {
context.setRollbackOnly();
try {
Properties properties = new Properties();
InitialContext ic = new InitialContext(properties);
RPMRequestSessionBeanRemote RPMRq = (RPMRequestSessionBeanRemote) ic.lookup(RPMRequestSessionBeanRemote.class.getName());
RPMRq.updateRPMRqState(RPMRQID, "E");
} catch (Exception e1) { }
}}
现在,在第一次尝试块中,如果发生错误,则回滚事务。但是,在调用context.setrollbackonly()之后,不会执行try块事务。引发的异常是事务回滚。
发布于 2015-01-08 09:57:44
由于整个当前事务被标记为回滚,所以对EJB的第二次调用也将被回滚。您必须将@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)或@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)用于您的RPMRequestSessionBeanRemote bean,这取决于您是否也需要那里的事务。
发布于 2015-01-08 07:11:01
这就是人们所期望的行为。事务边界位于容器管理事务的方法级别。我认为是db插入的writeLog也将被回滚。在这种情况下,您应该考虑使用JTA,或者在单独的调用中写入db insert,作为发起调用的客户端处理异常的一部分。
EJB 1 (Requires){
try{
call EJB2 (requires new)
//throw exception
}catch (handle EJB2 exception){
writeLogInDB();
}
}https://stackoverflow.com/questions/27834617
复制相似问题