从 before_completion 同步操作捕获异常:org.hibernate.SessionException:会话已关闭!
我正在使用 Spring 和 Hibernate Envers 将记录插入审计表中。当Wicket应用程序(Web)调用服务时,我看到Spring使用OpenSessionViewFiler并将flushmode设置为Manual。 AuditProcess 类的 doBeforeTransactionCompletion 方法中的以下代码:
if (FlushMode.isManualFlushMode(session.getFlushMode())) {
IsManual 变为 true,然后它使用临时会话将记录插入审计表中。它运行良好。
我们在WebSphere中还有另一个应用EJB,Spring,Hibernate。当我们从 EJB 调用相同的服务时,刷新模式变为自动,并且在上述方法中的 AuditProcess 类中失败并出现错误:
"WTRN0074E: Exception caught from before_completion synchronization operation: org.hibernate.SessionException: Session is closed!"
请让我知道您解决此问题的想法:
[4/23/11 17:42:53:582 CDT] 00000023 RegisteredSyn E WTRN0074E: Exception caught from before_completion synchronization operation: org.hibernate.SessionException: Session is closed! at org.hibernate.impl.AbstractSessionImpl.errorIfClosed(AbstractSessionImpl.java:72) at org.hibernate.impl.SessionImpl.contains(SessionImpl.java:1739) at org.hibernate.envers.synchronization.AuditProcess.getCurrentRevisionData(AuditProcess.java:125) at org.hibernate.envers.synchronization.AuditProcess.executeInSession(AuditProcess.java:104) at org.hibernate.envers.synchronization.AuditProcess.doBeforeTransactionCompletion(AuditProcess.java:152) at org.hibernate.engine.ActionQueue$BeforeTransactionCompletionProcessQueue.beforeTransactionCompletion(ActionQueue.java:543) at org.hibernate.engine.ActionQueue.beforeTransactionCompletion(ActionQueue.java:216) at org.hibernate.impl.SessionImpl.beforeTransactionCompletion(SessionImpl.java:571) at org.hibernate.jdbc.JDBCContext.beforeTransactionCompletion(JDBCContext.java:250) at org.hibernate.transaction.synchronization.CallbackCoordinator.beforeCompletion(CallbackCoordinator.java:125) at org.hibernate.transaction.synchronization.HibernateSynchronizationImpl.beforeCompletion(HibernateSynchronizationImpl.java:51) at org.hibernate.transaction.WebSphereExtendedJTATransactionLookup$TransactionManagerAdapter$TransactionAdapter$1.invoke(WebSphereExtendedJTATransactionLookup.java:209) at $Proxy44.beforeCompletion(Unknown Source) at com.ibm.ws.jtaextensions.SynchronizationCallbackWrapper.beforeCompletion(SynchronizationCallbackWrapper.java:65) at com.ibm.ws.Transaction.JTA.RegisteredSyncs.distributeBefore(RegisteredSyncs.java:242) at com.ibm.ws.Transaction.JTA.TransactionImpl.prePrepare(TransactionImpl.java:2408) at com.ibm.ws.Transaction.JTA.TransactionImpl.stage1CommitProcessing(TransactionImpl.java:1641) at com.ibm.ws.Transaction.JTA.TransactionImpl.processCommit(TransactionImpl.java:1612) at com.ibm.ws.Transaction.JTA.TransactionImpl.commit(TransactionImpl.java:1547) at com.ibm.ws.Transaction.JTA.TranManagerImpl.commit(TranManagerImpl.java:247) at com.ibm.ws.Transaction.JTA.TranManagerSet.commit(TranManagerSet.java:167) at com.ibm.ws.uow.UOWManagerImpl.uowCommit(UOWManagerImpl.java:1055) at com.ibm.ws.uow.UOWManagerImpl.uowEnd(UOWManagerImpl.java:1025) at com.ibm.ws.uow.UOWManagerImpl.runUnderNewUOW(UOWManagerImpl.java:975) at com.ibm.ws.uow.UOWManagerImpl.runUnderUOW(UOWManagerImpl.java:509) at org.springframework.transaction.jta.WebSphereUowTransactionManager.execute(WebSphereUowTransactionManager.java:281) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:127) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202) at $Proxy66.getAocBufferData(Unknown Source) at com.cvscaremark.links.submitorder.SubmitOrderFacade.executeSubmitOrderServices(SubmitOrderFacade.java:59) at com.cvscaremark.links.submitorder.SubmitOrderBean.processSubmitOrder(SubmitOrderBean.java:129) at com.cvscaremark.links.submitorder.SubmitOrderBean.ejbTimeout(SubmitOrderBean.java:102) at com.ibm.ejs.container.TimedObjectWrapper.ejbTimeout(TimedObjectWrapper.java:90) at com.ibm.ejs.container.TimerTaskHandler.doWork(TimerTaskHandler.java:265) at com.ibm.ws.scheduler.AlarmListener.executeTaskWithNotification(AlarmListener.java:795) at com.ibm.ws.scheduler.AlarmListener.access$700(AlarmListener.java:120) at com.ibm.ws.scheduler.AlarmListener$TaskWork.doWork(AlarmListener.java:426) at com.ibm.ws.scheduler.AlarmListener$TaskWork.run(AlarmListener.java:212) at com.ibm.ws.asynchbeans.J2EEContext.run(J2EEContext.java:782) at com.ibm.ws.asynchbeans.ExecutionContextImpl.go(ExecutionContextImpl.java:85) at com.ibm.ws.scheduler.AlarmListener.fireTask(AlarmListener.java:1400) at com.ibm.ws.scheduler.AlarmListener.fired(AlarmListener.java:1318) at com.ibm.ws.asynchbeans.AlarmImpl.callListenerMethod(AlarmImpl.java:338) at com.ibm.ws.asynchbeans.timer.GenericTimer.run(GenericTimer.java:216) at com.ibm.ws.asynchbeans.J2EEContext.run(J2EEContext.java:1150) at com.ibm.ws.asynchbeans.AlarmImpl.runListenerAsCJWork(AlarmImpl.java:173) at com.ibm.ws.asynchbeans.am._Alarm.fireAlarm(_Alarm.java:332) at com.ibm.ws.asynchbeans.am._Alarm.run(_Alarm.java:229) at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1497)
感谢您的帮助, 文卡特
I am using Spring with Hibernate Envers to insert record into audit tables. When Wicket application (web) calls service, I see Spring uses OpenSessionViewFiler and sets flushmode to Manual. AuditProcess class the following code in doBeforeTransactionCompletion method:
if (FlushMode.isManualFlushMode(session.getFlushMode())) {
IsManual becomes true, then it uses temporary session to insert record into audit tables. It is working fine.
We have another application EJB, Spring, Hibernate in WebSphere. When we call the same service from EJB, flushmode becomes AUTO and it fails in AuditProcess class in above mentioned method with the error:
"WTRN0074E: Exception caught from before_completion synchronization operation: org.hibernate.SessionException: Session is closed!"
Please let me know your ideas to resolve this issue:
[4/23/11 17:42:53:582 CDT] 00000023 RegisteredSyn E WTRN0074E: Exception caught from before_completion synchronization operation: org.hibernate.SessionException: Session is closed! at org.hibernate.impl.AbstractSessionImpl.errorIfClosed(AbstractSessionImpl.java:72) at org.hibernate.impl.SessionImpl.contains(SessionImpl.java:1739) at org.hibernate.envers.synchronization.AuditProcess.getCurrentRevisionData(AuditProcess.java:125) at org.hibernate.envers.synchronization.AuditProcess.executeInSession(AuditProcess.java:104) at org.hibernate.envers.synchronization.AuditProcess.doBeforeTransactionCompletion(AuditProcess.java:152) at org.hibernate.engine.ActionQueue$BeforeTransactionCompletionProcessQueue.beforeTransactionCompletion(ActionQueue.java:543) at org.hibernate.engine.ActionQueue.beforeTransactionCompletion(ActionQueue.java:216) at org.hibernate.impl.SessionImpl.beforeTransactionCompletion(SessionImpl.java:571) at org.hibernate.jdbc.JDBCContext.beforeTransactionCompletion(JDBCContext.java:250) at org.hibernate.transaction.synchronization.CallbackCoordinator.beforeCompletion(CallbackCoordinator.java:125) at org.hibernate.transaction.synchronization.HibernateSynchronizationImpl.beforeCompletion(HibernateSynchronizationImpl.java:51) at org.hibernate.transaction.WebSphereExtendedJTATransactionLookup$TransactionManagerAdapter$TransactionAdapter$1.invoke(WebSphereExtendedJTATransactionLookup.java:209) at $Proxy44.beforeCompletion(Unknown Source) at com.ibm.ws.jtaextensions.SynchronizationCallbackWrapper.beforeCompletion(SynchronizationCallbackWrapper.java:65) at com.ibm.ws.Transaction.JTA.RegisteredSyncs.distributeBefore(RegisteredSyncs.java:242) at com.ibm.ws.Transaction.JTA.TransactionImpl.prePrepare(TransactionImpl.java:2408) at com.ibm.ws.Transaction.JTA.TransactionImpl.stage1CommitProcessing(TransactionImpl.java:1641) at com.ibm.ws.Transaction.JTA.TransactionImpl.processCommit(TransactionImpl.java:1612) at com.ibm.ws.Transaction.JTA.TransactionImpl.commit(TransactionImpl.java:1547) at com.ibm.ws.Transaction.JTA.TranManagerImpl.commit(TranManagerImpl.java:247) at com.ibm.ws.Transaction.JTA.TranManagerSet.commit(TranManagerSet.java:167) at com.ibm.ws.uow.UOWManagerImpl.uowCommit(UOWManagerImpl.java:1055) at com.ibm.ws.uow.UOWManagerImpl.uowEnd(UOWManagerImpl.java:1025) at com.ibm.ws.uow.UOWManagerImpl.runUnderNewUOW(UOWManagerImpl.java:975) at com.ibm.ws.uow.UOWManagerImpl.runUnderUOW(UOWManagerImpl.java:509) at org.springframework.transaction.jta.WebSphereUowTransactionManager.execute(WebSphereUowTransactionManager.java:281) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:127) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202) at $Proxy66.getAocBufferData(Unknown Source) at com.cvscaremark.links.submitorder.SubmitOrderFacade.executeSubmitOrderServices(SubmitOrderFacade.java:59) at com.cvscaremark.links.submitorder.SubmitOrderBean.processSubmitOrder(SubmitOrderBean.java:129) at com.cvscaremark.links.submitorder.SubmitOrderBean.ejbTimeout(SubmitOrderBean.java:102) at com.ibm.ejs.container.TimedObjectWrapper.ejbTimeout(TimedObjectWrapper.java:90) at com.ibm.ejs.container.TimerTaskHandler.doWork(TimerTaskHandler.java:265) at com.ibm.ws.scheduler.AlarmListener.executeTaskWithNotification(AlarmListener.java:795) at com.ibm.ws.scheduler.AlarmListener.access$700(AlarmListener.java:120) at com.ibm.ws.scheduler.AlarmListener$TaskWork.doWork(AlarmListener.java:426) at com.ibm.ws.scheduler.AlarmListener$TaskWork.run(AlarmListener.java:212) at com.ibm.ws.asynchbeans.J2EEContext.run(J2EEContext.java:782) at com.ibm.ws.asynchbeans.ExecutionContextImpl.go(ExecutionContextImpl.java:85) at com.ibm.ws.scheduler.AlarmListener.fireTask(AlarmListener.java:1400) at com.ibm.ws.scheduler.AlarmListener.fired(AlarmListener.java:1318) at com.ibm.ws.asynchbeans.AlarmImpl.callListenerMethod(AlarmImpl.java:338) at com.ibm.ws.asynchbeans.timer.GenericTimer.run(GenericTimer.java:216) at com.ibm.ws.asynchbeans.J2EEContext.run(J2EEContext.java:1150) at com.ibm.ws.asynchbeans.AlarmImpl.runListenerAsCJWork(AlarmImpl.java:173) at com.ibm.ws.asynchbeans.am._Alarm.fireAlarm(_Alarm.java:332) at com.ibm.ws.asynchbeans.am._Alarm.run(_Alarm.java:229) at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1497)
Thanks for your help,
Venkat
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有提到有关会话创建的详细信息。
使用 getCurrentSession() 创建的会话将返回绑定到当前正在运行的线程的会话。脸红了&自动关闭。如果使用了
openSession()
,那么必须在flush & 之后手动查看。 commit 等。您可以尝试使用以下配置之一。
current_session_context_class
更改为托管
。session.setFlushMode(FlushMode.MANUAL)
。Haven't mentioned details about session creation.
Session created using
getCurrentSession()
will return the session that is bound to the currently running thread & gets flushed & closed automatically. IfopenSession()
used, then have to look manually after flush & commit etc.You can try using one of the following configuration.
current_session_context_class
tomanaged
.session.setFlushMode(FlushMode.MANUAL)
.