Hibernate乐观锁无法Catch到org.hibernate.StaleObjectStateException

Hibernate乐观锁无法Catch到org.hibernate.StaleObjectStateException时,请Catch HibernateOptimisticLockingFailureException 试一下

catch (HibernateOptimisticLockingFailureException e)
{
        e.printStackTrace();
        if (((Exception) e.getMostSpecificCause()) instanceof StaleObjectStateException)
        {
               e.getMostSpecificCause().printStackTrace();
        }
}

  

Judging from the stacktrace, I'd say that it is the second explanation. The original exception has been caught and a HibernateOptimisticLockingFailureException has been created that wraps it. It is the latter exception you are seeing.

If you want to specifically handle the original exception, you probably need to catch HibernateOptimisticLockingFailureException (or a superclass), and then call the exception object's getMostSpecificCause() to extract the original exception for diagnosis.

地址:https://stackoverflow.com/questions/30236145/not-able-to-catch-org-hibernate-staleobjectstateexception

原文地址:https://www.cnblogs.com/foxting/p/9230525.html