private Serializable getIdentifier(Object value, SharedSessionContractImplementor session) throws HibernateException { try { return ForeignKeys.getEntityIdentifierIfNotUnsaved( session.bestGuessEntityName( value ), value, session ); } catch (TransientObjectException toe) { return null; } }
/** * Removes entity entries that have an equal identifier with the incoming entity instance * * @param list The list containing the entity instances * @param entityInstance The entity instance to match elements. * @param entityName The entity name * @param session The session */ public static void identityRemove( Collection list, Object entityInstance, String entityName, SharedSessionContractImplementor session) { if ( entityInstance != null && ForeignKeys.isNotTransient( entityName, entityInstance, null, session ) ) { final EntityPersister entityPersister = session.getFactory().getEntityPersister( entityName ); final Type idType = entityPersister.getIdentifierType(); final Serializable idOfCurrent = ForeignKeys.getEntityIdentifierIfNotUnsaved( entityName, entityInstance, session ); final Iterator itr = list.iterator(); while ( itr.hasNext() ) { final Serializable idOfOld = ForeignKeys.getEntityIdentifierIfNotUnsaved( entityName, itr.next(), session ); if ( idType.isEqual( idOfCurrent, idOfOld, session.getFactory() ) ) { itr.remove(); break; } } } }
/** * Find the transient unsaved entity dependencies that are non-nullable. * @return the transient unsaved entity dependencies that are non-nullable, * or null if there are none. */ public NonNullableTransientDependencies findNonNullableTransientEntities() { return ForeignKeys.findNonNullableTransientEntities( getPersister().getEntityName(), getInstance(), getState(), isEarlyInsert(), getSession() ); }
/** * Is this instance persistent or detached? * <p/> * If <tt>assumed</tt> is non-null, don't hit the database to make the determination, instead assume that * value; the client code must be prepared to "recover" in the case that this assumed result is incorrect. * * @param entityName The name of the entity * @param entity The entity instance * @param assumed The assumed return value, if avoiding database hit is desired * @param session The session * * @return {@code true} if the given entity is not transient (meaning it is either detached/persistent) */ @SuppressWarnings("SimplifiableIfStatement") public static boolean isNotTransient(String entityName, Object entity, Boolean assumed, SharedSessionContractImplementor session) { if ( entity instanceof HibernateProxy ) { return true; } if ( session.getPersistenceContext().isEntryFor( entity ) ) { return true; } // todo : shouldnt assumed be revered here? return !isTransient( entityName, entity, assumed, session ); }
final EntityPersister persister = source.getEntityPersister( event.getEntityName(), entity ); final Serializable id = persister.getIdentifier( entity, source ); if ( !ForeignKeys.isNotTransient( event.getEntityName(), entity, Boolean.FALSE, source ) ) { throw new TransientObjectException( "cannot lock an unsaved transient instance: " +
final NonNullableTransientDependencies nonNullableTransientEntities = new NonNullableTransientDependencies(); for ( int i = 0; i < types.length; i++ ) { collectNonNullableTransientEntities( nullifier, values[i],
ForeignKeys.isTransient( associatedEntityName, original, Boolean.FALSE, session ) ) {
final EntityPersister persister = source.getEntityPersister( event.getEntityName(), entity ); final Serializable id = persister.getIdentifier( entity, source ); if ( !ForeignKeys.isNotTransient( event.getEntityName(), entity, Boolean.FALSE, source ) ) { throw new TransientObjectException( "cannot lock an unsaved transient instance: " +
final Type[] subtypes = actype.getSubtypes(); for ( int j = 0; j < subvalues.length; j++ ) { collectNonNullableTransientEntities( nullifier, subvalues[j],
@Override public Object replace(Object original, Object target, SharedSessionContractImplementor session, Object owner, Map copyCache) throws HibernateException { if ( original == null ) { return null; } else { final String entityName = session.bestGuessEntityName( original ); final Serializable id = ForeignKeys.getEntityIdentifierIfNotUnsaved( entityName, original, session ); return session.internalLoad( entityName, id, eager, false ); } }
final java.util.Set currentSaving = new IdentitySet(); for ( Object current : currentElements ) { if ( current != null && ForeignKeys.isNotTransient( entityName, current, null, session ) ) { final EntityEntry ee = session.getPersistenceContext().getEntry( current ); if ( ee != null && ee.getStatus() == Status.SAVING ) { final Serializable currentId = ForeignKeys.getEntityIdentifierIfNotUnsaved( entityName, current, final Serializable oldId = ForeignKeys.getEntityIdentifierIfNotUnsaved( entityName, old, session ); if ( !currentIds.contains( useIdDirect ? oldId : new TypedValue( idType, oldId ) ) ) { res.add( old );
if ( isTransient( entityName, object, Boolean.FALSE, session ) ) { throw new TransientObjectException( "object references an unsaved transient instance - save the transient instance before flushing: " +
final EntityPersister persister = source.getEntityPersister( event.getEntityName(), entity ); final Serializable id = persister.getIdentifier( entity, source ); if ( !ForeignKeys.isNotTransient( event.getEntityName(), entity, Boolean.FALSE, source ) ) { throw new TransientObjectException( "cannot lock an unsaved transient instance: " +
/** * Find the transient unsaved entity dependencies that are non-nullable. * @return the transient unsaved entity dependencies that are non-nullable, * or null if there are none. */ public NonNullableTransientDependencies findNonNullableTransientEntities() { return ForeignKeys.findNonNullableTransientEntities( getEntityDescriptor().getEntityName(), getInstance(), getState(), isEarlyInsert(), getSession() ); }
NonNullableTransientDependencies nonNullableTransientEntities = new NonNullableTransientDependencies(); for ( int i = 0; i < types.length; i++ ) { collectNonNullableTransientEntities( nullifier, i,
@Override public Serializable disassemble(Object value, SharedSessionContractImplementor session, Object owner) throws HibernateException { if ( value == null ) { return null; } else { return new ObjectTypeCacheEntry( session.bestGuessEntityName( value ), ForeignKeys.getEntityIdentifierIfNotUnsaved( session.bestGuessEntityName( value ), value, session ) ); } }
public static void identityRemove( Collection list, Object object, String entityName, SessionImplementor session) throws HibernateException { if ( object!=null && ForeignKeys.isNotTransient(entityName, object, null, session) ) { final EntityPersister entityPersister = session.getFactory().getEntityPersister( entityName ); Type idType = entityPersister.getIdentifierType(); Serializable idOfCurrent = ForeignKeys.getEntityIdentifierIfNotUnsaved(entityName, object, session); Iterator itr = list.iterator(); while ( itr.hasNext() ) { Serializable idOfOld = ForeignKeys.getEntityIdentifierIfNotUnsaved(entityName, itr.next(), session); if ( idType.isEqual( idOfCurrent, idOfOld, session.getFactory() ) ) { itr.remove(); break; } } } }
@Override public void noCascade( EventSource session, Object parent, EntityPersister persister, Type propertyType, int propertyIndex) { if ( propertyType.isEntityType() ) { Object child = persister.getPropertyValue( parent, propertyIndex ); String childEntityName = ((EntityType) propertyType).getAssociatedEntityName( session.getFactory() ); if ( child != null && !isInManagedState( child, session ) && !(child instanceof HibernateProxy) //a proxy cannot be transient and it breaks ForeignKeys.isTransient && ForeignKeys.isTransient( childEntityName, child, null, session ) ) { String parentEntityName = persister.getEntityName(); String propertyName = persister.getPropertyNames()[propertyIndex]; throw new TransientPropertyValueException( "object references an unsaved transient instance - save the transient instance before flushing", childEntityName, parentEntityName, propertyName ); } } }
final EntityTypeDescriptor descriptor = source.getEntityDescriptor( event.getEntityName(), entity ); final Object id = descriptor.getIdentifier( entity, source ); if ( !ForeignKeys.isNotTransient( event.getEntityName(), entity, Boolean.FALSE, source ) ) { throw new TransientObjectException( "cannot lock an unsaved transient instance: " +
/** * Find the transient unsaved entity dependencies that are non-nullable. * @return the transient unsaved entity dependencies that are non-nullable, * or null if there are none. */ public NonNullableTransientDependencies findNonNullableTransientEntities() { return ForeignKeys.findNonNullableTransientEntities( getPersister().getEntityName(), getInstance(), getState(), isEarlyInsert(), getSession() ); }