@Override public Serializable disassemble( Object value, SharedSessionContractImplementor session, Object owner) throws HibernateException { if ( value == null ) { return null; } else { // cache the actual id of the object, not the value of the // property-ref, which might not be initialized Object id = ForeignKeys.getEntityIdentifierIfNotUnsaved( getAssociatedEntityName(), value, session ); if ( id == null ) { throw new AssertionFailure( "cannot cache a reference to an object with a null id: " + getAssociatedEntityName() ); } return getIdentifierType( session ).disassemble( id, session, owner ); } }
public EntityType manyToOne(String persistentClass) { return new ManyToOneType( typeScope, persistentClass ); }
@Override public boolean isDirty( Object old, Object current, boolean[] checkable, SharedSessionContractImplementor session) throws HibernateException { if ( isAlwaysDirtyChecked() ) { return isDirty( old, current, session ); } else { if ( isSame( old, current ) ) { return false; } Object oldid = getIdentifier( old, session ); Object newid = getIdentifier( current, session ); return getIdentifierType( session ).isDirty( oldid, newid, checkable, session ); } }
@Override public void beforeAssemble(Serializable oid, SharedSessionContractImplementor session) { scheduleBatchLoadIfNeeded( assembleId( oid, session ), session ); }
@Override public Object assemble( Serializable oid, SharedSessionContractImplementor session, Object owner) throws HibernateException { //TODO: currently broken for unique-key references (does not detect // change to unique key property of the associated object) Serializable id = assembleId( oid, session ); if ( id == null ) { return null; } else { return resolveIdentifier( id, session ); } }
@Override public boolean isDirty( Object old, Object current, SharedSessionContractImplementor session) throws HibernateException { if ( isSame( old, current ) ) { return false; } Object oldid = getIdentifier( old, session ); Object newid = getIdentifier( current, session ); return getIdentifierType( session ).isDirty( oldid, newid, session ); }
@Override public boolean isModified( Object old, Object current, boolean[] checkable, SharedSessionContractImplementor session) throws HibernateException { if ( current == null ) { return old!=null; } if ( old == null ) { // we already know current is not null... return true; } // the ids are fully resolved, so compare them with isDirty(), not isModified() return getIdentifierOrUniqueKeyType( session.getFactory() ) .isDirty( old, getIdentifier( current, session ), session ); }
public Serializable disassemble(Object value, SessionImplementor session, Object owner) throws HibernateException { if ( isNotEmbedded(session) ) { return getIdentifierType(session).disassemble(value, session, owner); } if (value==null) { return null; } else { // cache the actual id of the object, not the value of the // property-ref, which might not be initialized Object id = ForeignKeys.getEntityIdentifierIfNotUnsaved( getAssociatedEntityName(), value, session ); if (id==null) { throw new AssertionFailure( "cannot cache a reference to an object with a null id: " + getAssociatedEntityName() ); } return getIdentifierType(session).disassemble(id, session, owner); } }
Type type = q.getReturnTypes()[0]; assertTrue( type instanceof ManyToOneType ); assertEquals( ( (ManyToOneType) type ).getAssociatedEntityName(), "org.hibernate.test.hql.Zoo" ); zoo = (Zoo) q.list().get(0); assertEquals( zoo.getMammals().size(), 1 );
public int getColumnSpan(Mapping mapping) throws MappingException { // our column span is the number of columns in the PK return getIdentifierOrUniqueKeyType( mapping ).getColumnSpan( mapping ); }
public Object assemble( Serializable oid, SessionImplementor session, Object owner) throws HibernateException { //TODO: currently broken for unique-key references (does not detect // change to unique key property of the associated object) Serializable id = assembleId( oid, session ); if ( isNotEmbedded( session ) ) { return id; } if ( id == null ) { return null; } else { return resolveIdentifier( id, session ); } }
@Override public Object hydrate( ResultSet rs, String[] names, SharedSessionContractImplementor session, Object owner) throws HibernateException, SQLException { // return the (fully resolved) identifier value, but do not resolve // to the actual referenced entity instance // NOTE: the owner of the association is not really the owner of the id! // First hydrate the ID to check if it is null. // Don't bother resolving the ID if hydratedKeyState[i] is null. // Implementation note: if id is a composite ID, then resolving a null value will // result in instantiating an empty composite if AvailableSettings#CREATE_EMPTY_COMPOSITES_ENABLED // is true. By not resolving a null value for a composite ID, we avoid the overhead of instantiating // an empty composite, checking if it is equivalent to null (it should be), then ultimately throwing // out the empty value. final Object hydratedId = getIdentifierOrUniqueKeyType( session.getFactory() ) .hydrate( rs, names, session, null ); final Serializable id; if ( hydratedId != null ) { id = (Serializable) getIdentifierOrUniqueKeyType( session.getFactory() ) .resolve( hydratedId, session, null ); } else { id = null; } scheduleBatchLoadIfNeeded( id, session ); return id; }
public Object assemble(Serializable oid, SessionImplementor session, Object owner) throws HibernateException { //TODO: currently broken for unique-key references (does not detect // change to unique key property of the associated object) Serializable id = (Serializable) getIdentifierType(session).assemble(oid, session, null); //the owner of the association is not the owner of the id if ( isNotEmbedded(session) ) return id; if (id==null) { return null; } else { return resolveIdentifier(id, session); } }
EntityPersister persister = session.getFactory().getEntityPersister( getAssociatedEntityName() ); EntityKey entityKey = new EntityKey( id, persister, session.getEntityMode() ); if ( !session.getPersistenceContext().containsEntity( entityKey ) ) { boolean[] checkable, SessionImplementor session) throws HibernateException { if ( isAlwaysDirtyChecked() ) { return isDirty( old, current, session );
private Serializable assembleId(Serializable oid, SharedSessionContractImplementor session) { //the owner of the association is not the owner of the id return ( Serializable ) getIdentifierType( session ).assemble( oid, session, null ); }
public Object hydrate(ResultSet rs, String[] names, SessionImplementor session, Object owner) throws HibernateException, SQLException { Serializable id = (Serializable) getIdentifierOrUniqueKeyType( session.getFactory() ) .nullSafeGet(rs, names, session, null); //note that the owner of the association is not really the owner of the id! if (id!=null) scheduleBatchLoad(id, session); return id; }
@Override public boolean[] toColumnNullness(Object value, Mapping mapping) { boolean[] result = new boolean[ getColumnSpan( mapping ) ]; if ( value != null ) { Arrays.fill( result, true ); } return result; }
public void nullSafeSet(PreparedStatement st, Object value, int index, boolean[] settable, SessionImplementor session) throws HibernateException, SQLException { getIdentifierOrUniqueKeyType( session.getFactory() ) .nullSafeSet(st, getIdentifier(value, session), index, settable, session); }
public boolean isDirty( Object old, Object current, SessionImplementor session) throws HibernateException { if ( isSame( old, current ) ) { return false; } Object oldid = getIdentifier( old, session ); Object newid = getIdentifier( current, session ); return getIdentifierType( session ).isDirty( oldid, newid, session ); }
public Serializable disassemble( Object value, SessionImplementor session, Object owner) throws HibernateException { if ( isNotEmbedded( session ) ) { return getIdentifierType( session ).disassemble( value, session, owner ); } if ( value == null ) { return null; } else { // cache the actual id of the object, not the value of the // property-ref, which might not be initialized Object id = ForeignKeys.getEntityIdentifierIfNotUnsaved( getAssociatedEntityName(), value, session ); if ( id == null ) { throw new AssertionFailure( "cannot cache a reference to an object with a null id: " + getAssociatedEntityName() ); } return getIdentifierType( session ).disassemble( id, session, owner ); } }