-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Expect StaleObjectStateException but get HibernateException
PostPosted: Wed Oct 11, 2006 8:26 pm 
Beginner
Beginner

Joined: Thu May 05, 2005 11:12 pm
Posts: 26
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


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 15, 2006 8:25 pm 
Newbie

Joined: Wed Jan 18, 2006 7:30 pm
Posts: 4
I presume it's not the obvious problem that you don't have a <version ...> element defined??

Have you turned on debugging for org.hibernate.sql? In some circumstances (which I have never figured out) Hibernate will update a record before it deletes it. Could that be happening here?

I can't comment on Hibernate 2 but have definitely received a StaleObjectException in this situation with Hibernate 3.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 15, 2006 8:29 pm 
Newbie

Joined: Wed Jan 18, 2006 7:30 pm
Posts: 4
Oh, sorry, I see it happens in the delete. Hmm, no other suggestions I'm afraid!


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 15, 2006 9:39 pm 
Beginner
Beginner

Joined: Thu May 05, 2005 11:12 pm
Posts: 26
Thanks for the reply.

Yes it happens in the delete, and we do get the expected behaviour during an update, and yes we have a <version> element :-)

Cheers anyway

Andrew


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.