从before_completion同步操作中捕获异常:org.hibernate.SessionException:会话已关闭!

时间:2011-04-23 22:58:40

标签: spring ejb websphere-6.1 hibernate-envers

我使用Spring和Hibernate Envers将记录插入到审计表中。当Wicket应用程序(web)调用服务时,我看到Spring使用OpenSessionViewFiler并将flushmode设置为Manual。 AuditProcess类在doBeforeTransactionCompletion方法中使用以下代码:

  if (FlushMode.isManualFlushMode(session.getFlushMode())) {

IsManual变为true,然后使用临时会话将记录插入审计表。它工作正常。

我们在WebSphere中有另一个应用程序EJB,Spring,Hibernate。当我们从EJB调用相同的服务时,flushmode变为AUTO,并且在上面提到的方法中它在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)

感谢您的帮助, Venkat

1 个答案:

答案 0 :(得分:0)

尚未提及有关会话创建的详细信息。

使用getCurrentSession()创建的会话将返回绑定到当前正在运行的线程&的会话。得到满脸通红自动关闭。如果使用了openSession(),则必须在刷新&提交等。

您可以尝试使用以下配置之一。

  • 在您的hibernate.cfg.xml中,将属性current_session_context_class更改为managed
  • 可以将刷新模式明确设置为session.setFlushMode(FlushMode.MANUAL)