When two users try and delete the same object, I expect to get a StaleObjectStateException as documented in the javadoc for StaleObjectStateException.
Thrown when a version number or timestamp check failed, indicating that the Session contained stale data (when using long transactions with versioning). Also occurs if we try delete or update a row that does not exist.
The examples do not shed any light, the reference doc does not shed any light, the faq's do not shed any light.
This looks similar to other threads and jira entries I have seen but not exactly the same. Can someone confirm that this is a known defect in hibernate 2.x and whether there is a fix or workaround for it.
Thanks, Andrew
Hibernate version: 2.1.3
Mapping documents: Not relevant
Code between sessionFactory.openSession() and session.close():
User 1:
Code:
MyClass myObj = (MyClass)session.get( MyClass.class, Long.valueOf("1234"))
User 2
Code:
MyClass myObj = (MyClass)session.get( MyClass.class, Long.valueOf("1234"))
User 1
Code:
session.delete( myObj );
transaction.commit()
User 2
Code:
session.delete (myObj )
transaction.commit()
However instead of getting a StaleObjectStateException as expected I get the following exception. Note that we have wrapped hibernate exceptions in our own classes to provide some abstraction from database implementation. The hibernate exception that is thrown is turned into the cause. Doesn't change the fact that we are getting a very general HibernateException thrown instead of the StaleObjectStateException as is documented in hibernate javadocs.
Full stack trace of any exception that occurs:
com.westpac.common.persistence.PersistenceException: net.sf.hibernate.HibernateException: SQL insert, update or delete failed (row not found)
at com.westpac.common.persistence.hibernate.HibernateUtils.doCommitTransaction(HibernateUtils.java:758)
at com.westpac.common.persistence.PersistenceUtils.commitTransaction(PersistenceUtils.java:1700)
at com.westpac.common.persistence.PersistenceUtils.commitTransaction(PersistenceUtils.java:1676)
at com.westpac.assist.accountmanagement.ui.struts.TPCBaseAction.execute(TPCBaseAction.java:118)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
at com.westpac.assist.accountmanagement.ui.processor.AccountManagementRequestProcessor.process(AccountManagementRequestProcessor.java:279)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1282)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1239)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:136)
at com.westpac.common.hostlogging.api.web.HostLoggingFilter.doFilter(HostLoggingFilter.java:268)
at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:142)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:121)
at com.westpac.assist.accountmanagement.ui.utils.AccountManagementFilter.doFilter(AccountManagementFilter.java:184)
at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:142)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:121)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain._doFilter(WebAppFilterChain.java:82)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:670)
at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:89)
at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:1878)
at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:84)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:472)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:411)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:288)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminaters(NewConnectionInitialReadCallback.java:201)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:103)
at com.ibm.ws.tcp.channel.impl.WorkQueueManager.requestComplete(WorkQueueManager.java:566)
at com.ibm.ws.tcp.channel.impl.WorkQueueManager.attemptIO(WorkQueueManager.java:619)
at com.ibm.ws.tcp.channel.impl.WorkQueueManager.workerRun(WorkQueueManager.java:952)
at com.ibm.ws.tcp.channel.impl.WorkQueueManager$Worker.run(WorkQueueManager.java:1039)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java(Compiled Code))
Caused by: net.sf.hibernate.HibernateException: SQL insert, update or delete failed (row not found)
at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:25)
at net.sf.hibernate.persister.EntityPersister.delete(EntityPersister.java:583)
at net.sf.hibernate.impl.ScheduledDeletion.execute(ScheduledDeletion.java:29)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2438)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2396)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2260)
at net.sf.hibernate.transaction.JTATransaction.commit(JTATransaction.java:52)
at com.westpac.common.persistence.hibernate.HibernateUtils.doCommitTransaction(HibernateUtils.java:749)
... 34 more
Name and version of the database you are using:
DB2 Version 8