我有兩個豆子:FirstBean和SecondBean。休眠:長CMT交易
FirstBean有方法方法1與REQUIRED事務屬性,SecondBean有方法方法2與NOT_SUPPORTED事務屬性。方法1調用方法2。
@Stateless
class FirstBean implement IFirstBean
{
ISecondBean secondBean;
@TransactionAttribute(TransactionAttributeType.REQUIRED)
void method1()
{
//...
secondBean.method2()
//...
}
}
@Stateless
class SecondBean implement ISecondBean
{
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
void method2()
{
//....
}
}
它運作良好。
但當方法2工作了很長一段時間(多則4-5分鐘),我得到在JBoss 4服務器
Caused by: java.lang.IllegalStateException: [com.arjuna.ats.internal.jta.transaction.arjunacore.inactive] [com.arjuna.ats.internal.jta.transaction.arjunacore.inactive] The transaction is not active!
at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1379)
at com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.commit(BaseTransaction.java:135)
和異常接下來在WebLogic 10.3
Caused By: org.hibernate.SessionException: Session is closed!
at org.hibernate.impl.AbstractSessionImpl.errorIfClosed(AbstractSessionImpl.java:49)
at org.hibernate.impl.SessionImpl.clear(SessionImpl.java:253)
方法一結束,例外的是拋出後
()'會'TransactionAttributeType.NOT_SUPPORTED'也 – Ilya
不,你真正想要活躍在'方法一交易()'。使用'TransactionAttributeType.REQUIRED'會導致方法參與一個事務,如果它存在,或者另外開始一個新事務。 – Perception
http://www.javahelp.info/2009/11/01/using-transactionattribute-in-submethods-on-same-ejb3-beans/ – Ilya