org.hibernate.type

Class ManyToOneType

Implemented Interfaces:
AssociationType, Serializable, Type

public class ManyToOneType
extends EntityType

A many-to-one association to an entity.
Author:
Gavin King

Field Summary

Fields inherited from class org.hibernate.type.EntityType

isEmbeddedInXML, uniqueKeyPropertyName

Constructor Summary

ManyToOneType(String className)
ManyToOneType(String entityName, String uniqueKeyPropertyName, boolean lazy, boolean unwrapProxy, boolean isEmbeddedInXML, boolean ignoreNotFound)
ManyToOneType(String className, boolean lazy)

Method Summary

Object
assemble(Serializable oid, SessionImplementor session, Object owner)
Reconstruct the object from its cached "disassembled" state.
void
beforeAssemble(Serializable oid, SessionImplementor session)
Called before assembling a query result set from the query cache, to allow batch fetching of entities missing from the second-level cache.
Serializable
disassemble(Object value, SessionImplementor session, Object owner)
Return a cacheable "disassembled" representation of the object.
int
getColumnSpan(Mapping mapping)
How many columns are used to persist this type.
ForeignKeyDirection
getForeignKeyDirection()
Object
hydrate(ResultSet rs, String[] names, SessionImplementor session, Object owner)
Retrieve an instance of the mapped class, or the identifier of an entity or collection, from a JDBC resultset.
boolean
isAlwaysDirtyChecked()
boolean
isDirty(Object old, Object current, boolean[] checkable, SessionImplementor session)
Should the parent be considered dirty, given both the old and current field or element value?
boolean
isDirty(Object old, Object current, SessionImplementor session)
Should the parent be considered dirty, given both the old and current field or element value?
boolean
isModified(Object old, Object current, boolean[] checkable, SessionImplementor session)
Has the parent object been modified, compared to the current database state?
protected boolean
isNullable()
boolean
isOneToOne()
void
nullSafeSet(PreparedStatement st, Object value, int index, boolean[] settable, SessionImplementor session)
Write an instance of the mapped class to a prepared statement, ignoring some columns.
void
nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session)
Write an instance of the mapped class to a prepared statement.
int[]
sqlTypes(Mapping mapping)
Return the SQL type codes for the columns mapped by this type.
boolean[]
toColumnNullness(Object value, Mapping mapping)
Given an instance of the type, return an array of boolean, indicating which mapped columns would be null.
boolean
useLHSPrimaryKey()

Methods inherited from class org.hibernate.type.EntityType

compare, deepCopy, fromXMLNode, getAssociatedEntityName, getAssociatedEntityName, getAssociatedJoinable, getHashCode, getIdentifier, getIdentifierOrUniqueKeyPropertyName, getIdentifierOrUniqueKeyType, getLHSPropertyName, getName, getOnCondition, getPropertyName, getRHSUniqueKeyPropertyName, getReturnedClass, getSemiResolvedType, isAssociationType, isEmbeddedInXML, isEntityType, isEqual, isMutable, isNotEmbedded, isNull, isNullable, isOneToOne, isReferenceToPrimaryKey, isSame, isXMLElement, loadByUniqueKey, nullSafeGet, nullSafeGet, replace, resolve, resolveIdentifier, setToXMLNode, toLoggableString, toString

Methods inherited from class org.hibernate.type.AbstractType

assemble, beforeAssemble, compare, disassemble, getHashCode, getHashCode, getSemiResolvedType, hydrate, isAnyType, isAssociationType, isCollectionType, isComponentType, isDirty, isEntityType, isEqual, isEqual, isModified, isSame, isXMLElement, replace, replaceNode, resolve, semiResolve

Constructor Details

ManyToOneType

public ManyToOneType(String className)

ManyToOneType

public ManyToOneType(String entityName,
                     String uniqueKeyPropertyName,
                     boolean lazy,
                     boolean unwrapProxy,
                     boolean isEmbeddedInXML,
                     boolean ignoreNotFound)

ManyToOneType

public ManyToOneType(String className,
                     boolean lazy)

Method Details

assemble

public Object assemble(Serializable oid,
                       SessionImplementor session,
                       Object owner)
            throws HibernateException
Reconstruct the object from its cached "disassembled" state.
Specified by:
assemble in interface Type
Overrides:
assemble in interface AbstractType
Parameters:
session - the session
owner - the parent entity object
Returns:
the the object

beforeAssemble

public void beforeAssemble(Serializable oid,
                           SessionImplementor session)
Called before assembling a query result set from the query cache, to allow batch fetching of entities missing from the second-level cache.
Specified by:
beforeAssemble in interface Type
Overrides:
beforeAssemble in interface AbstractType

disassemble

public Serializable disassemble(Object value,
                                SessionImplementor session,
                                Object owner)
            throws HibernateException
Return a cacheable "disassembled" representation of the object.
Specified by:
disassemble in interface Type
Overrides:
disassemble in interface AbstractType
Parameters:
value - the value to cache
session - the session
owner - optional parent entity object (needed for collections)
Returns:
the disassembled, deep cloned state

getColumnSpan

public int getColumnSpan(Mapping mapping)
            throws MappingException
How many columns are used to persist this type.
Specified by:
getColumnSpan in interface Type

getForeignKeyDirection

public ForeignKeyDirection getForeignKeyDirection()
Specified by:
getForeignKeyDirection in interface AssociationType

hydrate

public Object hydrate(ResultSet rs,
                      String[] names,
                      SessionImplementor session,
                      Object owner)
            throws HibernateException,
                   SQLException
Retrieve an instance of the mapped class, or the identifier of an entity or collection, from a JDBC resultset. This is useful for 2-phase property initialization - the second phase is a call to resolveIdentifier().
Specified by:
hydrate in interface Type
Overrides:
hydrate in interface AbstractType
Parameters:
rs -
names - the column names
session - the session
owner - the parent entity
Returns:
Object an identifier or actual value

isAlwaysDirtyChecked

public boolean isAlwaysDirtyChecked()
Specified by:
isAlwaysDirtyChecked in interface AssociationType

isDirty

public boolean isDirty(Object old,
                       Object current,
                       boolean[] checkable,
                       SessionImplementor session)
            throws HibernateException
Should the parent be considered dirty, given both the old and current field or element value?
Specified by:
isDirty in interface Type
Parameters:
old - the old value
current - the current value
checkable - which columns are actually updatable
session -
Returns:
true if the field is dirty

isDirty

public boolean isDirty(Object old,
                       Object current,
                       SessionImplementor session)
            throws HibernateException
Should the parent be considered dirty, given both the old and current field or element value?
Specified by:
isDirty in interface Type
Overrides:
isDirty in interface AbstractType
Parameters:
old - the old value
current - the current value
session -
Returns:
true if the field is dirty

isModified

public boolean isModified(Object old,
                          Object current,
                          boolean[] checkable,
                          SessionImplementor session)
            throws HibernateException
Has the parent object been modified, compared to the current database state?
Specified by:
isModified in interface Type
Overrides:
isModified in interface AbstractType
Parameters:
checkable - which columns are actually updatable
session -
Returns:
true if the field has been modified

isNullable

protected boolean isNullable()
Overrides:
isNullable in interface EntityType

isOneToOne

public boolean isOneToOne()
Overrides:
isOneToOne in interface EntityType

nullSafeSet

public void nullSafeSet(PreparedStatement st,
                        Object value,
                        int index,
                        boolean[] settable,
                        SessionImplementor session)
            throws HibernateException,
                   SQLException
Write an instance of the mapped class to a prepared statement, ignoring some columns. Implementors should handle possibility of null values. A multi-column type should be written to parameters starting from index.
Specified by:
nullSafeSet in interface Type
Parameters:
st -
value - the object to write
index - statement parameter index
settable - an array indicating which columns to ignore
session -

nullSafeSet

public void nullSafeSet(PreparedStatement st,
                        Object value,
                        int index,
                        SessionImplementor session)
            throws HibernateException,
                   SQLException
Write an instance of the mapped class to a prepared statement. Implementors should handle possibility of null values. A multi-column type should be written to parameters starting from index.
Specified by:
nullSafeSet in interface Type
Parameters:
st -
value - the object to write
index - statement parameter index
session -

sqlTypes

public int[] sqlTypes(Mapping mapping)
            throws MappingException
Return the SQL type codes for the columns mapped by this type. The codes are defined on java.sql.Types.
Specified by:
sqlTypes in interface Type
Returns:
the typecodes
See Also:
java.sql.Types

toColumnNullness

public boolean[] toColumnNullness(Object value,
                                  Mapping mapping)
Given an instance of the type, return an array of boolean, indicating which mapped columns would be null.
Specified by:
toColumnNullness in interface Type
Parameters:
value - an instance of the type

useLHSPrimaryKey

public boolean useLHSPrimaryKey()
Specified by:
useLHSPrimaryKey in interface AssociationType