-->
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.  [ 7 posts ] 
Author Message
 Post subject: Catch StaleObjectStateException - No Logging
PostPosted: Mon Sep 26, 2005 3:21 pm 
Newbie

Joined: Fri Apr 01, 2005 6:47 pm
Posts: 11
Using v3.1 Beta2. I have a situation where I'm storing a persisted object in a web session variable that is using a timestamp for optimistic locking. It is possible for that persisted object to change during the course of a session. So if I make a change to the object stored in the session and attempt to save it, I may get a StaleObjectStateException error. For this scenario, I am expecting this and I'm doing a try/catch. If I do get the error then I reload the persisted object, remake my change and then save again.

The problem is that even though I'm catching the StaleObjectStateException exception, it's still getting logged as a SEVERE error. I don't want this since in my situation I am expecting and handling it. So how could I prevent the exception from getting logged?

I understand a more graceful solution would be to check to see if the object has changed before attempting to save, but that would require doing extra SQL calls which may be unecessary. Only in rare circumstances in my scenario would the persisted object change during a session, so I don't want to have to check every time.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 26, 2005 10:51 pm 
Regular
Regular

Joined: Sat Aug 28, 2004 4:15 pm
Posts: 61
You could try turning off logging for the class that produces that specific error output.

On the other hand, does it matter if it gets logged? The fact that you handle it doesn't mean its not an exceptional case deserving of logging. Perhaps the level is what bothers you.


JOe

_________________
Joe W


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 27, 2005 12:51 pm 
Newbie

Joined: Fri Apr 01, 2005 6:47 pm
Posts: 11
I figured out a soltuion, although not ideal. I've decided to turn off all logging for org.hibernate. This way the exceptions will bubble up and can be handled in my code. If they aren't handled then they will cause a runtime exception and will get logged.

I wish there was a way to handle this on a case by case basis rather than turning off logging globally. I don't want SEVERE exceptions showing up in my logs if they are expected and handled in the code.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 27, 2005 7:43 pm 
Regular
Regular

Joined: Sat Aug 28, 2004 4:15 pm
Posts: 61
Just to share my thoughts on this...

I think you're viewing log output in a manner that is making this more difficult than it has to be.

Log output is just that....a snapshot in time status report of what happened in your system. SEVERE doesn't mean your application can't function.

From Javadocs on Sun:

Quote:
SEVERE is a message level indicating a serious failure.


That doesn't mean your application was poorly written or will fail. It just means that what happened at that snapshot in time is a SEVERE problem. Again, the fact that your application handles this situation means you're fine.

I'm not I've put enough into this to convince you that it is ok.

That said, you should be able to suppress Log messages just from the individual class that produced them, not all of org.hibernate.

joe

_________________
Joe W


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 27, 2005 8:41 pm 
Newbie

Joined: Fri Apr 01, 2005 6:47 pm
Posts: 11
"a snapshot in time status report of what happened in your system"

So why does the logging system allow you to choose severity levels? The answer is because there are some things you may not want to see in your log. Does that mean they didn't happen? Of course not. They happened, but they may not be worth logging.

In my opinion a "StaleObjectStateException" is a severe error if you weren't expecting it. But it is completely reasonable that you would catch this error and handle it, in which case it is no longer a severe error and should not show up as such in the log file. This applies to other Hibernate errors as well, such as those relating to constraint violations, etc. They should only show up in the log (in my opinion) if you aren't catching and handling them.

I understand that I could supress logging from just the Hibernate classes that produce just these specific exceptions that I'm handling. But even then there may be other exceptions thrown from those classes that I do want to get logged, or non-severe informational items. Ideally exceptions would not get logged by Hibernate if they were being caught.


Top
 Profile  
 
 Post subject: Catching StaleObjectStateException, But Still Get StackTrace
PostPosted: Sat Jul 14, 2007 1:13 pm 
Newbie

Joined: Wed May 23, 2007 12:58 am
Posts: 3
Location: Sactown ('da 916)
Yes, I agree with jim5359 . If you are catching and handling the StaleObjectStateException, Hibernate should not still print the stack trace.

I am having the same problem. I am catching and handling it, but I still get the stack trace on my console and in my log.

How do you disable this just for this class?
Is there an entry I can put in my log4j.properties file somewhere? p..57 and 58 discuss logging briefly, but I guess I need to look at the log4j documentation.

Thanks for any hints.

_________________
--
Bob R
Sun Certified Java Programmer
Sun Certified Java Developer
Sun Certified Web Component Developer


Last edited by consman on Sat Jul 14, 2007 2:01 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Catching StaleObjectStateException, But Still Get StackTrace
PostPosted: Sat Jul 14, 2007 1:52 pm 
Newbie

Joined: Wed May 23, 2007 12:58 am
Posts: 3
Location: Sactown ('da 916)
This may otherwise have adverse consequences, but it seems to work to take care of my problem for now. I just put a line down at the bottom of my log4j.properties file like this:

log4j.logger.org.hibernate.event.def.AbstractFlushingEventListener=fatal

If anyone has a better idea as to how to handle this. please let me know. Thanks.
--Bob

_________________
--
Bob R
Sun Certified Java Programmer
Sun Certified Java Developer
Sun Certified Web Component Developer


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.