Java org.hibernate.LazyInitializationException:无法初始化代理-无会话-很少发生

Java org.hibernate.LazyInitializationException:无法初始化代理-无会话-很少发生,java,hibernate,flush,Java,Hibernate,Flush,我的批处理程序抛出了一个LazyInitializationException异常。这种情况并非每次都发生。这种情况很少发生,当重新运行批处理时,记录会得到正确处理 我正在使用下面的代码刷新每100条记录的缓存 private void flushHibernateCache() { final String CM_FLUSH_HBM_CHACHE = "flushHibernateCache"; final String CM_CLEAR_HBM_CHACHE = "clear

我的批处理程序抛出了一个
LazyInitializationException
异常。这种情况并非每次都发生。这种情况很少发生,当重新运行批处理时,记录会得到正确处理

我正在使用下面的代码刷新每100条记录的缓存

private void flushHibernateCache() {
    final String CM_FLUSH_HBM_CHACHE = "flushHibernateCache";
    final String CM_CLEAR_HBM_CHACHE = "clearHibernateCache";
    BigInteger sessionLimit = getParameters().getSESSION_FLUSH_LIMIT();
    if (notNull(sessionLimit) && recordsProcessed.mod(sessionLimit).intValue() == 0) {
        FrameworkSession session = (FrameworkSession) SessionHolder.getSession();
        session.flush(CM_FLUSH_HBM_CHACHE);
        session.clear(CM_CLEAR_HBM_CHACHE);
    }
}
当我将要刷新的记录数从100增加到大于要处理的实际记录数时,批处理将正常运行

以下是错误日志:

18:21:53,687 [BATCHWorker:2] ERROR (com.splwg.base.support.cluster.ClusteredExecutionContext) An error has occurred while processing distributed grid work.  A rollback will be issued.  Processing of other work will continue.
com.splwg.base.api.batch.ThreadAbortedException: org.hibernate.LazyInitializationException: could not initialize proxy - no Session
    at com.splwg.base.api.batch.AbstractCommitStrategy.handleReplayableCommit(AbstractCommitStrategy.java:219)
    at com.splwg.base.api.batch.AbstractCommitStrategy.__AW_doCommit(AbstractCommitStrategy.java:201)
    at com.splwg.base.api.batch.AbstractCommitStrategy.doCommit(AbstractCommitStrategy.java)
    at com.splwg.base.api.batch.AbstractCommitStrategy.__AW_concreteExecuteWork(AbstractCommitStrategy.java:75)
    at com.splwg.base.api.batch.AbstractCommitStrategy.concreteExecuteWork(AbstractCommitStrategy.java)
    at com.splwg.base.api.batch.CommitEveryUnitStrategy.concreteExecuteWork(CommitEveryUnitStrategy.java:36)
    at com.splwg.base.api.batch.AbstractExecutionStrategy.__AW_executeWork(AbstractExecutionStrategy.java:243)
    at com.splwg.base.api.batch.AbstractExecutionStrategy.executeWork(AbstractExecutionStrategy.java)
    at com.splwg.base.support.batch.JavaBatchWork.executeThreadWork(JavaBatchWork.java:109)
    at com.splwg.base.support.batch.JavaBatchWork.access$300(JavaBatchWork.java:29)
    at com.splwg.base.support.batch.JavaBatchWork$DoExecuteWorkInSession.doBatchWorkInSession(JavaBatchWork.java:92)
    at com.splwg.base.support.batch.BatchWorkInSessionExecutable.__AW_run(BatchWorkInSessionExecutable.java:62)
    at com.splwg.base.support.batch.BatchWorkInSessionExecutable.run(BatchWorkInSessionExecutable.java)
    at com.splwg.base.support.batch.JavaBatchWork.doExecuteWork(JavaBatchWork.java:51)
    at com.splwg.base.support.grid.AbstractGridWork.executeWork(AbstractGridWork.java:72)
    at com.splwg.base.support.cluster.ThreadWork.processBatchWork(ThreadWork.java:54)
    at com.splwg.base.support.cluster.BatchWorkManager.processWork(BatchWorkManager.java:78)
    at com.tangosol.coherence.commonj.WorkManager$ScheduleWork.__AW_run(WorkManager.java:2266)
    at com.tangosol.coherence.commonj.WorkManager$ScheduleWork.run(WorkManager.java)
    at com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.InvocationService.__AW_onInvocationRequest(InvocationService.CDB:12)
    at com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.InvocationService.onInvocationRequest(InvocationService.CDB)
    at com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.InvocationService$InvocationRequest.run(InvocationService.CDB:1)
    at com.tangosol.coherence.component.util.DaemonPool$WrapperTask.run(DaemonPool.CDB:1)
    at com.tangosol.coherence.component.util.DaemonPool$WrapperTask.run(DaemonPool.CDB:32)
    at com.tangosol.coherence.component.util.DaemonPool$Daemon.__AW_onNotify(DaemonPool.CDB:65)
    at com.tangosol.coherence.component.util.DaemonPool$Daemon.onNotify(DaemonPool.CDB)
    at com.tangosol.coherence.component.util.Daemon.__AW_run(Daemon.CDB:51)
    at com.tangosol.coherence.component.util.Daemon.run(Daemon.CDB)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.hibernate.LazyInitializationException: could not initialize proxy - no Session
    at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:149)
    at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:195)
    at org.hibernate.bytecode.cglib.proxy.pojo.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:190)
    at org.hibernate.proxy.HibernateProxy$$EnhancerByCGLIB$$c8ddfe27.getThreads(<generated>)
    at com.splwg.base.domain.batch.batchRun.BatchThread_Per.getOwningLists(BatchThread_Per.java:191)
    at com.splwg.base.support.context.FrameworkSession.__AW_registerChange(FrameworkSession.java:1694)
    at com.splwg.base.support.context.FrameworkSession.registerChange(FrameworkSession.java)
    at com.splwg.base.support.api.AbstractBusinessEntity.registerChange(AbstractBusinessEntity.java:153)
    at com.splwg.base.support.context.FrameworkSession.__AW_registerChanges(FrameworkSession.java:1303)
    at com.splwg.base.support.context.FrameworkSession.registerChanges(FrameworkSession.java)
    at com.splwg.base.support.context.FrameworkSession.setDTOCalled(FrameworkSession.java:1290)
    at com.splwg.base.support.api.AbstractBusinessEntity.completeSetAbstractDTO(AbstractBusinessEntity.java:166)
    at com.splwg.base.support.api.AbstractBusinessEntity$2.run(AbstractBusinessEntity.java:281)
    at com.splwg.base.support.api.AbstractBusinessEntity$JumpToFrameworkRunner.run(AbstractBusinessEntity.java:372)
    at com.splwg.base.support.interception.SessionInterceptionManager.notifyGenericCallStackJump(SessionInterceptionManager.java:290)
    at com.splwg.base.support.context.FrameworkSession.notifyGenericCallStackJump(FrameworkSession.java:2311)
    at com.splwg.base.support.api.AbstractBusinessEntity.executeCallStackJump(AbstractBusinessEntity.java:298)
    at com.splwg.base.support.api.AbstractBusinessEntity.setDTOEtc(AbstractBusinessEntity.java:284)
    at com.splwg.base.domain.batch.batchRun.BatchThreadInstance_Per.setDTO(BatchThreadInstance_Per.java:124)
    at com.splwg.base.api.batch.AbstractExecutionStrategy.updateUnitsProcessed(AbstractExecutionStrategy.java:140)
    at com.splwg.base.api.batch.AbstractExecutionStrategy.updateRestartDataAndCommit(AbstractExecutionStrategy.java:112)
    at com.splwg.base.api.batch.AbstractCommitStrategy.saveRestartDataAndCommit(AbstractCommitStrategy.java:259)
    at com.splwg.base.api.batch.AbstractCommitStrategy.__AW_doCommit(AbstractCommitStrategy.java:191)
    ... 27 more
18:21:53687[BATCHWorker:2]错误(com.splwg.base.support.cluster.ClusteredExecutionContext)处理分布式网格工作时出错。将发布回滚。其他工作将继续进行。
com.splwg.base.api.batch.ThreadAbortedException:org.hibernate.LazyInitializationException:无法初始化代理-无会话
位于com.splwg.base.api.batch.AbstractCommitStrategy.HandlerReplayableCommit(AbstractCommitStrategy.java:219)
位于com.splwg.base.api.batch.AbstractCommitStrategy.\uuuuAw\uDoCommit(AbstractCommitStrategy.java:201)
位于com.splwg.base.api.batch.AbstractCommitStrategy.doCommit(AbstractCommitStrategy.java)
在com.splwg.base.api.batch.AbstractCommitStrategy.\uuuuAW\uConcreteExecuteWork上(AbstractCommitStrategy.java:75)
位于com.splwg.base.api.batch.AbstractCommitStrategy.concreteExecuteWork(AbstractCommitStrategy.java)
位于com.splwg.base.api.batch.CommitteeVeryunitstrategy.concreteExecuteWork(committeeVeryunitstrategy.java:36)
位于com.splwg.base.api.batch.AbstractExecutionStrategy.\uuuuAW\uExecuteWork(AbstractExecutionStrategy.java:243)
位于com.splwg.base.api.batch.AbstractExecutionStrategy.executeWork(AbstractExecutionStrategy.java)
位于com.splwg.base.support.batch.JavaBatchWork.executeThreadWork(JavaBatchWork.java:109)
在com.splwg.base.support.batch.JavaBatchWork.access$300(JavaBatchWork.java:29)
位于com.splwg.base.support.batch.JavaBatchWork$DoExecuteWorkInSession.doBatchWorkInSession(JavaBatchWork.java:92)
在com.splwg.base.support.batch.BatchWorkInSessionExecutable.\uuuuaw\urun(BatchWorkInSessionExecutable.java:62)
位于com.splwg.base.support.batch.BatchWorkInSessionExecutable.run(BatchWorkInSessionExecutable.java)
位于com.splwg.base.support.batch.JavaBatchWork.doExecuteWork(JavaBatchWork.java:51)
位于com.splwg.base.support.grid.AbstractGridWork.executeWork(AbstractGridWork.java:72)
位于com.splwg.base.support.cluster.ThreadWork.processBatchWork(ThreadWork.java:54)
位于com.splwg.base.support.cluster.BatchWorkManager.processWork(BatchWorkManager.java:78)
在com.tangosol.coherence.commonj.WorkManager$ScheduleWork.\uuuuaw\urun(WorkManager.java:2266)
位于com.tangosol.coherence.commonj.WorkManager$ScheduleWork.run(WorkManager.java)
位于com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.InvocationService.\uuuuuaw\uOnInvocationRequest(InvocationService.CDB:12)
位于com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.InvocationService.onInvocationRequest(InvocationService.CDB)
位于com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.InvocationService$InvocationRequest.run(InvocationService.CDB:1)
在com.tangosol.coherence.component.util.DaemonPool$WrapperTask.run(DaemonPool.CDB:1)上
在com.tangosol.coherence.component.util.DaemonPool$WrapperTask.run(DaemonPool.CDB:32)上
位于com.tangosol.coherence.component.util.DaemonPool$Daemon.\uuuuuaw\uonnotify(DaemonPool.CDB:65)
位于com.tangosol.coherence.component.util.DaemonPool$Daemon.onNotify(DaemonPool.CDB)
位于com.tangosol.coherence.component.util.Daemon.\uuuuuaw\urun(Daemon.CDB:51)
位于com.tangosol.coherence.component.util.Daemon.run(Daemon.CDB)
运行(Thread.java:745)
原因:org.hibernate.LazyInitializationException:无法初始化代理-无会话
位于org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:149)
位于org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:195)
位于org.hibernate.bytecode.cglib.proxy.pojo.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:190)
在org.hibernate.proxy.HibernateProxy$$enhancerbyglib$$c8ddfe27.getThreads()上
位于com.splwg.base.domain.batch.batchRun.BatchThread_Per.getowningList(BatchThread_Per.java:191)
在com.splwg.base.support.context.FrameworkSession.\uuuAW\uRegisterChange(FrameworkSession.java:1694)上
在com.splwg.base.support.context.FrameworkSession.registerChange(FrameworkSession.java)上
位于com.splwg.base.support.api.AbstractBusinessEntity.registerChange(AbstractBusinessEntity.java:153)
在com.splwg.base.support.context.FrameworkSession.\uuuAW\uRegisterChanges(FrameworkSession.java:1303)上
在com.splwg.base.support.context.FrameworkSession.registerChanges(FrameworkSession.java)上
位于com.splwg.base.support.context.FrameworkSession.setDTOCalled(FrameworkSession.java:1290)
位于com.splwg.base.support.api.AbstractBusinessEntity.completeSetAbstractDTO(AbstractBusinessEntity.java:166)
位于com.splwg.base.support.api.AbstractBusinessEntity$2.run(AbstractBusinessEntity.java:281)
位于com.splwg.base.support.api.AbstractBusinessEntity$JumpToFrameworkRunner.run(AbstractBusinessEntity.java:372)
位于com.splwg.base.support.interception.SessionInterceptionManager.notifyGenericCallStackJump(SessionInterceptionManager.java:290)
位于com.splwg.base.support.context.FrameworkSession.notifyGenericCallStackJump(FrameworkSession.java:2311)
位于com.splwg.base.support.api.AbstractBusinessEntity.executeCallStackJump(AbstractBusinessEntity.java:298)
在com.splwg.base.support.api.AbstractBusinessEntity.setDTOEtc(AbstractBusinessEntity.java:284)
位于com.splwg.base.domain.batch.batchRun.BatchThreadInstance_Per.setDTO(BatchThreadInstance_Per.java:124)
位于com.splwg.base.api.batch.AbstractExecutionStrategy.updateUnitsProcessed(摘要