StaleObjectStateException:由于stalestate而导致persist失败

时间:2014-11-17 06:24:25

标签: java spring hibernate spring-batch

我被困在这里,无法找出 StaleObjectStateException 的任何解决方案。
我已经阅读了这些StackOverflow Article 1StackOverflow Article 2,但是得不到多少......

我的抽象类代码:

try {
            long currentTime = System.currentTimeMillis();
            try{
                session = sessionFactory.getCurrentSession();
            }catch(Exception e){}
            if (session == null) {
                session = sessionFactory.openSession();
                isNewSession = true;
            }

            if (baseDO.isDeleted()) {
                log.debug("Deleting instance" + baseDO.getId());
                session.delete(baseDO);
            } else if (baseDO.isInserted() || baseDO.isNew()) {
                log.debug("Inserting instance");
                baseDO.setVersionID(1l);
                session.saveOrUpdate(this.getDOName(), baseDO);
            } else if (baseDO.isUpdated()) {
                log.debug("Updating instance");
                //Session session = sessionFactory.getCurrentSession();
                baseDO = (B) session.merge(this.getDOName(), baseDO);
                session.saveOrUpdate(this.getDOName(), baseDO); 

/ * 我正好在线上 * /

                // sessionFactory.getCurrentSession().saveOrUpdate(baseDO);

                log.debug("Updated instance" + baseDO);
            } else {
                log.warn("*** Not persisting any Data for " + getDOName() + " ***");
            }
            log.debug("persist successful");
        } 
        catch(StaleObjectStateException stoe){
            log.error("persist failed due to stalestate", stoe);
            throw stoe;
        }
        catch (RuntimeException re) {
            log.error("persist failed", re);
            throw re;
        }
        finally {
            if (session != null && isNewSession)
                session.close();
        }

这是我得到的错误:

11:13:52,339 INFO  [stdout] (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#62b093c8-1) [ERROR] 11:13:52 AbstractDAO - persist failed due to stalestate

11:13:52,339 INFO  [stdout] (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#62b093c8-1) org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [com.c2lbiz.symbiosys.insurance.businesscommon.dataobjects.payment.CompensationPayableDO#18238]

11:13:52,339 INFO  [stdout] (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#62b093c8-1)   at org.hibernate.event.def.DefaultMergeEventListener.entityIsDetached(DefaultMergeEventListener.java:261)

11:13:52,339 INFO  [stdout] (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#62b093c8-1)   at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:120)

11:13:52,339 INFO  [stdout] (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#62b093c8-1)   at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:53)

11:13:52,339 INFO  [stdout] (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#62b093c8-1)   at org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:677)

11:13:52,339 INFO  [stdout] (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#62b093c8-1)   at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:661)

11:13:52,339 INFO  [stdout] (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#62b093c8-1)   at com.c2lbiz.symbiosys.systemcommon.dao.hibernate.AbstractDAO.save(AbstractDAO.java:549)

11:13:52,339 INFO  [stdout] (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#62b093c8-1)   at com.c2lbiz.symbiosys.systemcommon.business.BaseBO.save(BaseBO.java:291)

11:13:52,339 INFO  [stdout] (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#62b093c8-1)   at com.c2lbiz.symbiosys.interfaces.job.GlPostingWriter.execute(GlPostingWriter.java:63)

11:13:52,339 INFO  [stdout] (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#62b093c8-1)   at com.c2lbiz.symbiosys.interfaces.job.GlPostingWriter.execute(GlPostingWriter.java:1)

11:13:52,339 INFO  [stdout] (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#62b093c8-1)   at sun.reflect.GeneratedMethodAccessor598.invoke(Unknown Source)

11:13:52,339 INFO  [stdout] (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#62b093c8-1)   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

11:13:52,354 INFO  [stdout] (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#62b093c8-1)   at java.lang.reflect.Method.invoke(Unknown Source)

11:13:52,354 INFO  [stdout] (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#62b093c8-1)   at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:318)

11:13:52,354 INFO  [stdout] (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#62b093c8-1)   at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)

11:13:52,354 INFO  [stdout] (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#62b093c8-1)   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)

11:13:52,354 INFO  [stdout] (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#62b093c8-1)   at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:90)

11:13:52,354 INFO  [stdout] (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#62b093c8-1)   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)

11:13:52,354 INFO  [stdout] (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#62b093c8-1)   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)

11:13:52,354 INFO  [stdout] (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#62b093c8-1)   at $Proxy62.execute(Unknown Source)

11:13:52,354 INFO  [stdout] (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#62b093c8-1)   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

11:13:52,354 INFO  [stdout] (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#62b093c8-1)   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

11:13:52,354 INFO  [stdout] (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#62b093c8-1)   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

11:13:52,354 INFO  [stdout] (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#62b093c8-1)   at java.lang.reflect.Method.invoke(Unknown Source)

11:13:52,354 INFO  [stdout] (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#62b093c8-1)   at org.springframework.util.MethodInvoker.invoke(MethodInvoker.java:273)

11:13:52,354 INFO  [stdout] (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#62b093c8-1)   at org.springframework.batch.item.adapter.AbstractMethodInvokingDelegator.doInvoke(AbstractMethodInvokingDelegator.java:117)

11:13:52,354 INFO  [stdout] (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#62b093c8-1)   at org.springframework.batch.item.adapter.AbstractMethodInvokingDelegator.invokeDelegateMethodWithArgument(AbstractMethodInvokingDelegator.java:72)

11:13:52,354 INFO  [stdout] (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#62b093c8-1)   at org.springframework.batch.item.adapter.ItemWriterAdapter.write(ItemWriterAdapter.java:36)

11:13:52,354 INFO  [stdout] (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#62b093c8-1)   at org.springframework.batch.core.step.item.SimpleChunkProcessor.writeItems(SimpleChunkProcessor.java:171)

11:13:52,354 INFO  [stdout] (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#62b093c8-1)   at org.springframework.batch.core.step.item.SimpleChunkProcessor.doWrite(SimpleChunkProcessor.java:150)

11:13:52,370 INFO  [stdout] (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#62b093c8-1)   at org.springframework.batch.core.step.item.SimpleChunkProcessor.write(SimpleChunkProcessor.java:269)

11:13:52,370 INFO  [stdout] (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#62b093c8-1)   at org.springframework.batch.core.step.item.SimpleChunkProcessor.process(SimpleChunkProcessor.java:194)

11:13:52,371 INFO  [stdout] (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#62b093c8-1)   at org.springframework.batch.core.step.item.ChunkOrientedTasklet.execute(ChunkOrientedTasklet.java:74)

11:13:52,371 INFO  [stdout] (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#62b093c8-1)   at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:386)

11:13:52,371 INFO  [stdout] (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#62b093c8-1)   at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:130)

11:13:52,371 INFO  [stdout] (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#62b093c8-1)   at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:264)

11:13:52,371 INFO  [stdout] (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#62b093c8-1)   at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:76)

11:13:52,371 INFO  [stdout] (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#62b093c8-1)   at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:367)

11:13:52,371 INFO  [stdout] (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#62b093c8-1)   at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:214)

11:13:52,371 INFO  [stdout] (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#62b093c8-1)   at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:143)

11:13:52,371 INFO  [stdout] (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#62b093c8-1)   at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:250)

11:13:52,371 INFO  [stdout] (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#62b093c8-1)   at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:195)

11:13:52,371 INFO  [stdout] (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#62b093c8-1)   at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:135)

11:13:52,371 INFO  [stdout] (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#62b093c8-1)   at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:61)

11:13:52,371 INFO  [stdout] (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#62b093c8-1)   at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:60)

11:13:52,371 INFO  [stdout] (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#62b093c8-1)   at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:144)

11:13:52,371 INFO  [stdout] (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#62b093c8-1)   at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:124)

11:13:52,371 INFO  [stdout] (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#62b093c8-1)   at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:135)

11:13:52,371 INFO  [stdout] (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#62b093c8-1)   at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:281)

11:13:52,371 INFO  [stdout] (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#62b093c8-1)   at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:120)

11:13:52,371 INFO  [stdout] (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#62b093c8-1)   at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

11:13:52,371 INFO  [stdout] (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#62b093c8-1)   at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

11:13:52,371 INFO  [stdout] (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#62b093c8-1)   at java.lang.Thread.run(Unknown Source)

请帮助,
在此先感谢。

0 个答案:

没有答案