在我们的一个生产环境中,我们首先在线程上连续出现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);
}
答案 0 :(得分:0)
您在更新后重新获取persistObj
吗? (您的代码没有显示)
如果没有,则会因为您更新persistObj
而发生这种情况。更新完成后,您的类实例中有一个“旧”版本的persistObj
。如果您想再次更新persistObj
,则需要再次获取persistObj
的“当前”版本。