在我们的一个生产环境中,我们在线程首次出现后不断地在线程上获得 hibernatestaleobject 异常。这一直持续到我们重新启动服务器。
环境:oracle 10g,WAS 6.1,Hibernate 2.1
堆栈跟踪如下。
我们无法在任何其他环境中模拟这一点。
net.sf.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect) for com.cmp1.project1.hibernate.gen.Prjexe instance with identifier: 37120123
at net.sf.hibernate.persister.AbstractEntityPersister.check(AbstractEntityPersister.java:506)
at net.sf.hibernate.persister.EntityPersister.update(EntityPersister.java:687)
at net.sf.hibernate.persister.EntityPersister.update(EntityPersister.java:642)
at net.sf.hibernate.impl.ScheduledUpdate.execute(ScheduledUpdate.java:52)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2418)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2372)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2240)
at com.cmp1.project1.hibernate.client.HibernateClient.update(HibernateClient.java:214)
at com.cmp1.project1.hibernate.client.HibernateClient.update(HibernateClient.java:165)
at com.cmp1.project1.util.project1Utils.persist(project1Utils.java:3018)
at com.cmp1.project1.util.project1Utils.update(project1Utils.java:1166)
at com.cmp1.project1.service.allocation.AllocationImpl.insert(AllocationImpl.java:917)
at com.cmp1.project1.service.allocation.AllocationImpl.create(AllocationImpl.java:239)
at com.cmp1.project1.ejb.allocation.AllocationBean.create(AllocationBean.java:91)
at com.cmp1.project1.ejb.allocation.EJSLocalStatelessAllocation_9d8d9db9.create(EJSLocalStatelessAllocation_9d8d9db9.java:55)
at com.cmp1.project1.ejb.allocation.AllocationClient.create(AllocationClient.java:116)
at com.cmp1.project1.service.processor.ProcessorImpl.processAllocationInstruction(ProcessorImpl.java:2917)
at com.cmp1.project1.service.processor.ProcessorImpl.processFIXMessage(ProcessorImpl.java:568)
at com.cmp1.project1.service.processor.ProcessorImpl.processSingleMessage(ProcessorImpl.java:459)
at com.cmp1.project1.service.processor.ProcessorImpl.processStagedMessage(ProcessorImpl.java:368)
at com.cmp1.project1.service.processor.ProcessorImpl.processMessage(ProcessorImpl.java:259)
at com.cmp1.project1.ejb.processor.ProcessorBean.processMessage(ProcessorBean.java:85)
at com.cmp1.project1.ejb.processor.EJSLocalStatelessProcessor_ac8a6492.processMessage(EJSLocalStatelessProcessor_ac8a6492.java:23)
at com.cmp1.project1.ejb.processor.ProcessorClient.processMessage(ProcessorClient.java:117)
at com.cmp1.project1.service.inbound.AsynchInboundHandlerImpl.process(AsynchInboundHandlerImpl.java:56)
at com.cmp1.project1.ejb.serviceactivator.ServiceActivatorBean.onMessage(ServiceActivatorBean.java:77)
at com.ibm.ejs.jms.listener.MDBWrapper$PriviledgedOnMessage.run(MDBWrapper.java:302)
at com.ibm.ws.security.util.AccessController.doPrivileged(AccessController.java:63)
at com.ibm.ejs.jms.listener.MDBWrapper.callOnMessage(MDBWrapper.java:271)
at com.ibm.ejs.jms.listener.MDBWrapper.onMessage(MDBWrapper.java:240)
at com.ibm.mq.jms.MQSession.run(MQSession.java:1695)
at com.ibm.ejs.jms.JMSSessionHandle.run(JMSSessionHandle.java:1040)
at com.ibm.ejs.jms.listener.ServerSession.connectionConsumerOnMessage(ServerSession.java:1030)
at com.ibm.ejs.jms.listener.ServerSession.onMessage(ServerSession.java:710)
at com.ibm.ejs.jms.listener.ServerSession.dispatch(ServerSession.java:677)
at sun.reflect.GeneratedMethodAccessor83.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:592)
at com.ibm.ejs.jms.listener.ServerSessionDispatcher.dispatch(ServerSessionDispatcher.java:44)
at com.ibm.ejs.container.MDBWrapper.onMessage(MDBWrapper.java:96)
at com.ibm.ejs.container.MDBWrapper.onMessage(MDBWrapper.java:132)
at com.ibm.ejs.jms.listener.ServerSession.run(ServerSession.java:535)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1497)
代码片段:
if(persistObj == null)
return;
Session session = sess;
try {
if(session == null)
session = HibernateUtil.getSession();
if(LOG.isDebugEnabled() &&
!(persistObj instanceof NonLoggable))
log("update", persistObj);
session.update(persistObj);
if(flush)
session.flush();
} catch(StaleObjectStateException ex) {
throw new HibernateStaleObjectException(ex);
}