我正在使用JBOSS EAP 6.x.即使已声明事务属性,TransactionRequiredException
我有ejb.method1()
其中标注有事务属性@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
ejb.method2()
其中标注有交易属性@TransactionAttribute(TransactionAttributeType.SUPPORTS)
我打电话ejb.method2()
从ejb.method1()
类似下面
ejb.method() {
//some operation
ejb.method2();
//some operation
}
ejb2.method2() {
//some operation
merge(entity1); // no error here
try {
sendMessageToMQ // no error here} catch(Exception e) {
entity.setStatus("SUCCESS");
} catch() {Expcetion) {
entity1.setStatus("ERROR");
} finally {
merge(entity1); // Throwing Caused by: javax.persistence.TransactionRequiredException: JBAS011469: Transaction is required to perform this operation (either use a transaction or extended persistence context
}
}
如果执行在一分钟内完成,代码将起作用,但在大约3分钟后,它会失败,出现以下异常。事务超时设置为15分钟。
Caused by: javax.persistence.TransactionRequiredException: JBAS011469: Transaction is required to perform this operation (either use a transaction or extended persistence context
看起来像是在第一次merge()之后由于某些原因,事务已经结束。 merge()是entityManager的方法还是你的方法? – Ermal
好抓..合并是我们的框架方法,它基于某些逻辑在内部创建某些版本化记录和历史记录,并使用实体管理器的合并执行插入和更新。我将尝试在具有事务属性的新方法中移动第二个合并,并在此处进行更新。 –
或者可能是第一次合并根本不需要。 –