public HibernateOptimisticLockingFailureException(StaleObjectStateException ex) { super(ex.getEntityName(), ex.getIdentifier(), ex); }
private Object[] getDatabaseSnapshot(SessionImplementor session, EntityPersister persister, Serializable id) { if ( persister.isSelectBeforeUpdateRequired() ) { Object[] snapshot = session.getPersistenceContext() .getDatabaseSnapshot( id, persister ); if ( snapshot == null ) { //do we even really need this? the update will fail anyway.... if ( session.getFactory().getStatistics().isStatisticsEnabled() ) { session.getFactory().getStatistics() .optimisticFailure( persister.getEntityName() ); } throw new StaleObjectStateException( persister.getEntityName(), id ); } return snapshot; } // TODO: optimize away this lookup for entities w/o unsaved-value="undefined" final EntityKey entityKey = session.generateEntityKey( id, persister ); return session.getPersistenceContext().getCachedDatabaseSnapshot( entityKey ); } }
public HibernateOptimisticLockingFailureException(StaleObjectStateException ex) { super(ex.getEntityName(), ex.getIdentifier(), ex); }
protected boolean check( int rows, Serializable id, int tableNumber, Expectation expectation, PreparedStatement statement) throws HibernateException { try { expectation.verifyOutcome( rows, statement, -1 ); } catch (StaleStateException e) { if ( !isNullableTable( tableNumber ) ) { if ( getFactory().getStatistics().isStatisticsEnabled() ) { getFactory().getStatistics().optimisticFailure( getEntityName() ); } throw new StaleObjectStateException( getEntityName(), id ); } return false; } catch (TooManyRowsAffectedException e) { throw new HibernateException( "Duplicate identifier in table for: " + MessageHelper.infoString( this, id, getFactory() ) ); } catch (Throwable t) { return false; } return true; }
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.internalLoad( sose.getEntityName(), identifier, false, true); 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; }
/** * Check the version of the object in the <tt>ResultSet</tt> against * the object version in the session cache, throwing an exception * if the version numbers are different */ private void checkVersion( final int i, final Loadable persister, final Serializable id, final Object entity, final ResultSet rs, final SharedSessionContractImplementor session) throws HibernateException, SQLException { Object version = session.getPersistenceContext().getEntry( entity ).getVersion(); if ( version != null ) { //null version means the object is in the process of being loaded somewhere else in the ResultSet final VersionType versionType = persister.getVersionType(); final Object currentVersion = versionType.nullSafeGet( rs, getEntityAliases()[i].getSuffixedVersionAliases(), session, null ); if ( !versionType.isEqual( version, currentVersion ) ) { if ( session.getFactory().getStatistics().isStatisticsEnabled() ) { session.getFactory().getStatistics().optimisticFailure( persister.getEntityName() ); } throw new StaleObjectStateException( persister.getEntityName(), id ); } } }
return new ObjectOptimisticLockingFailureException(hibEx.getEntityName(), hibEx.getIdentifier(), ex);
session.getFactory().getStatistics().optimisticFailure( persister.getEntityName() ); throw new StaleObjectStateException( persister.getEntityName(), entityKey.getIdentifier() );
return new ObjectOptimisticLockingFailureException(hibEx.getEntityName(), hibEx.getIdentifier(), ex);
factory.getStatistics().optimisticFailure( getLockable().getEntityName() ); throw new StaleObjectStateException( getLockable().getEntityName(), id );
public HibernateOptimisticLockingFailureException(StaleObjectStateException ex) { super(ex.getEntityName(), ex.getIdentifier(), ex); }
factory.getStatistics().optimisticFailure( getLockable().getEntityName() ); throw new StaleObjectStateException( getLockable().getEntityName(), id );
public HibernateOptimisticLockingFailureException(StaleObjectStateException ex) { super(ex.getEntityName(), ex.getIdentifier(), ex); }
factory.getStatistics().optimisticFailure( getLockable().getEntityName() ); throw new StaleObjectStateException( getLockable().getEntityName(), id );
public HibernateOptimisticLockingFailureException(StaleObjectStateException ex) { super(ex.getEntityName(), ex.getIdentifier(), ex); }
source.getFactory().getStatistics().optimisticFailure( entityName ); throw new StaleObjectStateException( entityName, id );
/** * The constructor. * * @param cause is the {@link StaleObjectStateException}. */ public OptimisticLockingExceptionHibernate(StaleObjectStateException cause) { super(cause, getEntityRepresentation(cause.getEntityName()), cause.getIdentifier()); }
factory.getStatistics().optimisticFailure( lockable.getEntityName() ); throw new StaleObjectStateException( lockable.getEntityName(), id );
private static net.sf.hibernate.StaleObjectStateException adaptStaleObjectStateException( final org.hibernate.StaleStateException ex) { org.hibernate.StaleObjectStateException stex = ex instanceof org.hibernate.StaleObjectStateException ? (org.hibernate.StaleObjectStateException) ex : null; final String message = ex.getMessage(); final String entityName = stex != null ? stex.getEntityName() : null; final Serializable identifier = stex != null ? stex.getIdentifier() : null; return new net.sf.hibernate.StaleObjectStateException(null, identifier) { @Override public String getMessage() { return message; } @Override public Class getPersistentClass() { try { return entityName != null ? Class.forName(entityName) : Object.class; } catch (ClassNotFoundException ex) { return Object.class; } } @Override public String toString() { return toStringWithClassName(this, net.sf.hibernate.StaleObjectStateException.class); } }; }
factory.getStatistics().optimisticFailure( lockable.getEntityName() ); throw new StaleObjectStateException( lockable.getEntityName(), id );