我的批处理程序抛出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
我无法确定发生此错误的原因。请帮忙。
答案 0 :(得分:0)
你试图在没有hibernate会话的地方调用BatchThread_Per.getOwningLists()。
org.hibernate.LazyInitializationException
是Hibernate中的常见错误。当您尝试在hibernate会话范围之外初始化hibernate对象时,它会抛出。
请检查您的代码。