-->
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.  [ 8 posts ] 
Author Message
 Post subject: How to listen for StaleObjectStateException
PostPosted: Mon Nov 07, 2005 8:22 pm 
Beginner
Beginner

Joined: Tue Jun 14, 2005 12:14 pm
Posts: 37
Hi all,

I would like to intercept all optimistic-locking-related exception so that we can deal with it sensibly. We are using CMT (with JBoss), so there is no transaction demarcation within the code.

I see Hibernate 3 has the listener concept. So, I create my listener that extends off the DefaultFlushEventListener, with its sole purpose to intercept the StaleStateException and throwing my own application exception. A couple of questions:

1) Is it ok to rethrow the StaleStateException as something else at this level?
2) Is there any other listener I need to implement to catch optimistic-locking related exception?

Thanks in advance,
Liem


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 07, 2005 8:34 pm 
Beginner
Beginner

Joined: Tue Jun 14, 2005 12:14 pm
Posts: 37
A note is that my application exception is also a RuntimeException.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 08, 2005 6:41 pm 
Beginner
Beginner

Joined: Tue Jun 14, 2005 12:14 pm
Posts: 37
Anyone with this need out there? I assume the need to be notified for an optimistic-lock exception should be a good one, since that is one of the few HibernateException that the application can do something about it.

Liem


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 09, 2005 4:02 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
JAVA "catch" block listens for exceptions, do you need something "better" ?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 09, 2005 4:09 am 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
not too sure if "we can deal with it sensibly" other than to retry the unit of work or redirect the user to a pretty error page. have heard more than once on the forum that if you get any exception in the Session - rollback transaction and throw away the Session.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 09, 2005 5:27 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
It is common to forward request to the same page with the same data and message "$data was modified by $user .... " on version conflict, so just catch exception, rollback transaction and close session, if you need modified data then load it in the new session. But it must be better to avoid this exception using hidden version field in HTML form without any state on webserver, it can help to avoid scalability problems.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 09, 2005 10:47 am 
Beginner
Beginner

Joined: Tue Jun 14, 2005 12:14 pm
Posts: 37
Hi,

Thanks for all your suggestions...

But, remember I am in CMT, so all transaction demarcations are done declaratively. I don't get the exception until the container tries to commit, fails, and rollbacks the exception, in which case the client gets a RemoteException which wraps a JBossRollBackException which wraps the Hibernate StaleObjectStateException.

So, now you see, I have to do 2 things to handle this--not sure if this is the recommended way to do it:

1) Introduce another higher-level facade business layer, which calls the transactional layer that does Hibernate stuff, so that I catch this particular RemoteException and retry.

2) I need to specifically "peel" off the RemoteExeption 2 levels down and look for this particular StaleObjectStateException to detect an optimistic-lock failure. Other Hibernate failures are considered non-recoverable by us.

My point is, since the StaleObjectStateException is so "special", I think there is great value to have a notifier for it, so applications can choose to handle it or not.

Also, back to my original question...

Is it sufficient to "catch" optimistic-lock exception by extending off the DefaultFlushEventListener, intercepting the StaleStateException and throwing my own RuntimeException?

Is there any other listener I need to implement to catch optimistic-locking related exception?

Thanks,
Liem


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 10, 2005 1:00 pm 
Beginner
Beginner

Joined: Tue Jun 14, 2005 12:14 pm
Posts: 37
Should the StaleObjectStateException notification be an enhancement request for Hibernate? Before I file a JIRA, just want to make sure that there are enough people out there with similar needs as I do. Of course if there is another sensible workaround, then I will buy that too :)

Thanks,
Liem


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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.