java - 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
课堂上:</p>
我抛出异常
throw new Exception();
然后这将捕获CBRTask.java
,然后导致数据库调用命中错误。
假设它不应该发生。因为这段代码在 Hibernate 3 中运行良好。在我迁移到 hibernate 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。
推荐阅读
- git - 合并多个合并时减少噪音的Git程序?
- python - 列表函数分别列出所有字符
- c# - UWP - 命令参数为空
- c - 显示完美数字及其加法器
- spring - 我们如何在 Spring 中将 HttpSession 与 SessionRegistry 同步
- c# - 为什么是 IDisposable 接口?
- javascript - 如何在 DataTables 中的“上一个”和“下一个”按钮之间显示有关页码的信息?
- powershell - PowerShell New-CommandWrapper :为以下参数提供值
- angular - AG-Grid Export to excel 用于多行的主从导出
- python - 在熊猫中获得相同数量的每种二进制数据的最佳方法