protected PersistenceException wrapStaleStateException(StaleStateException e) {
   PersistenceException pe;
   if (e instanceof StaleObjectStateException) {
     final StaleObjectStateException sose = (StaleObjectStateException) e;
     final Serializable identifier = sose.getIdentifier();
     if (identifier != null) {
       try {
         final Object entity = sharedSessionContract.load(sose.getEntityName(), identifier);
         if (entity instanceof Serializable) {
           // avoid some user errors regarding boundary crossing
           pe = new OptimisticLockException(e.getMessage(), e, entity);
         } else {
           pe = new OptimisticLockException(e.getMessage(), e);
         }
       } catch (EntityNotFoundException enfe) {
         pe = new OptimisticLockException(e.getMessage(), e);
       }
     } else {
       pe = new OptimisticLockException(e.getMessage(), e);
     }
   } else {
     pe = new OptimisticLockException(e.getMessage(), e);
   }
   return pe;
 }
 /** {@inheritDoc} */
 public PersistenceException wrapStaleStateException(StaleStateException e) {
   PersistenceException pe;
   if (e instanceof StaleObjectStateException) {
     StaleObjectStateException sose = (StaleObjectStateException) e;
     Serializable identifier = sose.getIdentifier();
     if (identifier != null) {
       try {
         Object entity = getRawSession().load(sose.getEntityName(), identifier);
         if (entity instanceof Serializable) {
           // avoid some user errors regarding boundary crossing
           pe = new OptimisticLockException(null, e, entity);
         } else {
           pe = new OptimisticLockException(e);
         }
       } catch (EntityNotFoundException enfe) {
         pe = new OptimisticLockException(e);
       }
     } else {
       pe = new OptimisticLockException(e);
     }
   } else {
     pe = new OptimisticLockException(e);
   }
   return pe;
 }