@SuppressWarnings({ "ThrowableInstanceNeverThrown" })
PersistenceException wrapStaleStateException(StaleStateException e) {
PersistenceException pe;
if ( e instanceof StaleObjectStateException ) {
StaleObjectStateException sose = ( StaleObjectStateException ) e;
Serializable identifier = sose.getIdentifier();
if ( identifier != null ) {
Object entity = session.load( sose.getEntityName(), identifier );
if ( entity instanceof Serializable ) {
//avoid some user errors regarding boundary crossing
pe = new OptimisticLockException( null, e, entity );
}
else {