org.hibernate.HibernateException:迁移到 Hibernate 5 后,当前事务未进行



>我有一个类文件,CBRTask.java

在这个CBRTask.java中,我有一些代码如下:

@Autowired
private CbrService cbrService;
public CBRPayment execute() {
try {
cbrService.sendCR( this.entity );
// If I manually throw Exception here, no problem in catch
catch (Exception exception) {
// do something to call db, but hit error
}
}

然后在我CbrService课上:

我抛出异常

throw new Exception();

然后这将捕获CBRTask.java,然后导致数据库调用命中错误。

假设它不应该发生。因为这段代码在 Hibernate 3 中运行良好。在我迁移到休眠 5 后,然后只命中。

以下是错误日志:

org.hibernate.HibernateException: Current transaction is not in progress
at org.hibernate.context.internal.JTASessionContext.currentSession(JTASessionContext.java:81)
at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:721)

如果我在 CBRPayment 类中手动抛出异常,并在同一个地方捕获,问题就不会发生。

它实际上不是因为将Hibernate 3升级到Hibernate 5。但它是关于事务管理器的。在此之前,我使用的是WebSphereUowTransactionManager,每次捕获异常后,这个东西都会自动创建新事务。

当我来到 Jboss 环境时,我正在使用JTATransactionManager,不知道为什么这个管理器会使用现有的事务,即使有一个事务被捕获。

我所做的是,将GlobalRollbackOnParticipationFailure更改为 false。

最新更新