[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-3442) StaleObjectStateException logs unnecessary stacktrace

Tom van den Berge (JIRA) noreply at atlassian.com
Thu Aug 21 15:36:49 EDT 2008


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-3442?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_30976 ] 

Tom van den Berge commented on HHH-3442:
----------------------------------------

Could you please explain how I can change the logging in such a way that StaleObjectStateException is no longer logged, but all other HibernateExceptions are?

With my limited knowledge of log4j, I could change the level of this class to FATAL, so that ERROR won't be logged anymore. Of course other ERROR log messages won't be logged either. This is surely not what you want.


Please clarify the suggested workaround.

> StaleObjectStateException logs unnecessary stacktrace
> -----------------------------------------------------
>
>                 Key: HHH-3442
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3442
>             Project: Hibernate3
>          Issue Type: Improvement
>    Affects Versions: 3.3.0.GA
>            Reporter: Tom van den Berge
>            Priority: Minor
>
> When using optimistic locking, and stale state is detected, a StaleObjectStateException is thrown. This exception is caught in AbstractFlushingEventListener, logged as error, including a stacktrace, and then thrown again.
> It would be better not to log the stacktrace in this situation, since it's up to the client code to deal with the exception. If the client code doesn't handle optimistic locking exceptions, it can choose to log the stacktrace itself, or otherwise do something useful with the exception, such as retrying. Currently, the stacktrace is always logged by Hibernate, also if the client code recovers from the exception, which is a bit confusing when looking at the logs. 
> Also the fact that this particular exception is logged with severity ERROR is inappropriate. It's up to the client code to decide if it's an error.
> I suggest the following change to AbstractFlushingEventListener:
> Current code:
> catch (HibernateException he) {
>        log.error("Could not synchronize database state with session", he);
>        throw he;
> }
> Suggested code:
> catch (StaleObjectStateException e) {
>        log.warn("Could not synchronize database state with session", e.getMessage());
>        throw e;
> }
> catch (HibernateException he) {
>        log.error("Could not synchronize database state with session", he);
>        throw he;
> }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the hibernate-issues mailing list