FileDocCategorySizeDatePackage
ManyToOneType.javaAPI DocHibernate 3.2.57206Thu Jun 15 11:38:04 BST 2006org.hibernate.type

ManyToOneType

public class ManyToOneType extends EntityType
A many-to-one association to an entity.
author
Gavin King

Fields Summary
private final boolean
ignoreNotFound
Constructors Summary
public ManyToOneType(String className)

		this( className, false );
	
public ManyToOneType(String className, boolean lazy)

		super( className, null, !lazy, true, false );
		this.ignoreNotFound = false;
	
public ManyToOneType(String entityName, String uniqueKeyPropertyName, boolean lazy, boolean unwrapProxy, boolean isEmbeddedInXML, boolean ignoreNotFound)

		super( entityName, uniqueKeyPropertyName, !lazy, isEmbeddedInXML, unwrapProxy );
		this.ignoreNotFound = ignoreNotFound;
	
Methods Summary
public java.lang.Objectassemble(java.io.Serializable oid, org.hibernate.engine.SessionImplementor session, java.lang.Object owner)

		
		//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 );
		}
	
private java.io.SerializableassembleId(java.io.Serializable oid, org.hibernate.engine.SessionImplementor session)

		//the owner of the association is not the owner of the id
		return ( Serializable ) getIdentifierType( session ).assemble( oid, session, null );
	
public voidbeforeAssemble(java.io.Serializable oid, org.hibernate.engine.SessionImplementor session)

		scheduleBatchLoadIfNeeded( assembleId( oid, session ), session );
	
public java.io.Serializabledisassemble(java.lang.Object value, org.hibernate.engine.SessionImplementor session, java.lang.Object owner)


		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 );
		}
	
public intgetColumnSpan(org.hibernate.engine.Mapping mapping)

		// our column span is the number of columns in the PK
		return getIdentifierOrUniqueKeyType( mapping ).getColumnSpan( mapping );
	
public ForeignKeyDirectiongetForeignKeyDirection()

		return ForeignKeyDirection.FOREIGN_KEY_FROM_PARENT;
	
public java.lang.Objecthydrate(java.sql.ResultSet rs, java.lang.String[] names, org.hibernate.engine.SessionImplementor session, java.lang.Object owner)

		// 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!
		Serializable id = (Serializable) getIdentifierOrUniqueKeyType( session.getFactory() )
				.nullSafeGet( rs, names, session, null );
		scheduleBatchLoadIfNeeded( id, session );
		return id;
	
public booleanisAlwaysDirtyChecked()

		// If we have <tt>not-found="ignore"</tt> association mapped to a
		// formula, we always need to dirty check it, so we can update the
		// second-level cache
		return ignoreNotFound;
	
public booleanisDirty(java.lang.Object old, java.lang.Object current, org.hibernate.engine.SessionImplementor session)

		if ( isSame( old, current, session.getEntityMode() ) ) {
			return false;
		}
		Object oldid = getIdentifier( old, session );
		Object newid = getIdentifier( current, session );
		return getIdentifierType( session ).isDirty( oldid, newid, session );
	
public booleanisDirty(java.lang.Object old, java.lang.Object current, boolean[] checkable, org.hibernate.engine.SessionImplementor session)

		if ( isAlwaysDirtyChecked() ) {
			return isDirty( old, current, session );
		}
		else {
			if ( isSame( old, current, session.getEntityMode() ) ) {
				return false;
			}
			Object oldid = getIdentifier( old, session );
			Object newid = getIdentifier( current, session );
			return getIdentifierType( session ).isDirty( oldid, newid, checkable, session );
		}
		
	
public booleanisModified(java.lang.Object old, java.lang.Object current, boolean[] checkable, org.hibernate.engine.SessionImplementor session)

		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 );
	
protected booleanisNullable()

		return ignoreNotFound;
	
public booleanisOneToOne()

		return false;
	
public voidnullSafeSet(java.sql.PreparedStatement st, java.lang.Object value, int index, org.hibernate.engine.SessionImplementor session)

		getIdentifierOrUniqueKeyType( session.getFactory() )
				.nullSafeSet( st, getIdentifier( value, session ), index, session );
	
public voidnullSafeSet(java.sql.PreparedStatement st, java.lang.Object value, int index, boolean[] settable, org.hibernate.engine.SessionImplementor session)

		getIdentifierOrUniqueKeyType( session.getFactory() )
				.nullSafeSet( st, getIdentifier( value, session ), index, settable, session );
	
private voidscheduleBatchLoadIfNeeded(java.io.Serializable id, org.hibernate.engine.SessionImplementor session)
Register the entity as batch loadable, if enabled

		//cannot batch fetch by unique key (property-ref associations)
		if ( uniqueKeyPropertyName == null && id != null ) {
			EntityPersister persister = session.getFactory().getEntityPersister( getAssociatedEntityName() );
			EntityKey entityKey = new EntityKey( id, persister, session.getEntityMode() );
			if ( !session.getPersistenceContext().containsEntity( entityKey ) ) {
				session.getPersistenceContext()
						.getBatchFetchQueue()
						.addBatchLoadableEntityKey( entityKey );
			}
		}
	
public int[]sqlTypes(org.hibernate.engine.Mapping mapping)

		return getIdentifierOrUniqueKeyType( mapping ).sqlTypes( mapping );
	
public boolean[]toColumnNullness(java.lang.Object value, org.hibernate.engine.Mapping mapping)

		boolean[] result = new boolean[ getColumnSpan( mapping ) ];
		if ( value != null ) {
			Arrays.fill( result, true );
		}
		return result;
	
public booleanuseLHSPrimaryKey()

		return false;