Transactions BMT EJB不进行回滚
我有一个Bean管理事务无状态EJB。在这个EJB中,有一个方法,在该方法中,接收到一个将被更新的实体。若抛出异常,客户端将调用EJB中的另一个方法来将该实体状态更新为错误 EJB接口Transactions BMT EJB不进行回滚,transactions,ejb,rollback,Transactions,Ejb,Rollback,我有一个Bean管理事务无状态EJB。在这个EJB中,有一个方法,在该方法中,接收到一个将被更新的实体。若抛出异常,客户端将调用EJB中的另一个方法来将该实体状态更新为错误 EJB接口 @Remote interface EntityRemote { public void updateEntity(Entity entity) throws Exception; public void handleExcpetion(Entity entity, Exception exc
@Remote
interface EntityRemote {
public void updateEntity(Entity entity) throws Exception;
public void handleExcpetion(Entity entity, Exception exception);
}
EJB实现
@Stateless
@TransactionManagement(TransactionManagementType.BEAN)
public class EntitySessionBean implements EntityRemote {
@Resource
private UserTransaction tx;
public void updateEntity(Entity entity) throws Exception {
tx.begin();
try {
// make some manipulation, which can throw some Exception
enitityDAO.update(entity);
// Some more manipulation
tx.commit();
} catch(Exception e) {
tx.rollback();
throw e;
}
}
public void handleException(Entity entity, Exception exception) {
log.error(exception);
try {
tx.begin();
entity.setStatus(ERROR);
enitityDAO.update(entity);
tx.commit();
} catch (Exception e1) {
logger.exception(e1);
tx.rollback();
}
}
}
在客户端:
EntityRemote remote = // ...
Entity entity = // ...
try {
remote.updateEntity(entity);
} catch (Exception e) {
remote.handleException(entity, e);
}
如果在updateEntity()
中,在更新实体之后和提交之前引发了一些异常,就会出现我的问题。我验证了在数据库中不仅提交了来自handleException()
的修改,而且提交了在updateEntity()中完成的修改。这就像在updateEntity()
中执行的回滚没有任何效果
这里有什么问题