org.hibernate.type

Class OneToOneType

Implemented Interfaces:
AssociationType, Serializable, Type
Known Direct Subclasses:
SpecialOneToOneType

public class OneToOneType
extends EntityType

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

Field Summary

Fields inherited from class org.hibernate.type.EntityType

isEmbeddedInXML, uniqueKeyPropertyName

Constructor Summary

OneToOneType(String referencedEntityName, ForeignKeyDirection foreignKeyType, String uniqueKeyPropertyName, boolean lazy, boolean unwrapProxy, boolean isEmbeddedInXML, String entityName, String propertyName)

Method Summary

Object
assemble(Serializable oid, SessionImplementor session, Object owner)
Reconstruct the object from its cached "disassembled" state.
Serializable
disassemble(Object value, SessionImplementor session, Object owner)
Return a cacheable "disassembled" representation of the object.
int
getColumnSpan(Mapping session)
How many columns are used to persist this type.
ForeignKeyDirection
getForeignKeyDirection()
String
getPropertyName()
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()
We don't need to dirty check one-to-one because of how assemble/disassemble is implemented and because a one-to-one association is never dirty
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?
boolean
isNull(Object owner, SessionImplementor session)
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 session)
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

OneToOneType

public OneToOneType(String referencedEntityName,
                    ForeignKeyDirection foreignKeyType,
                    String uniqueKeyPropertyName,
                    boolean lazy,
                    boolean unwrapProxy,
                    boolean isEmbeddedInXML,
                    String entityName,
                    String propertyName)

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

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 session)
            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

getPropertyName

public String getPropertyName()
Overrides:
getPropertyName in interface EntityType

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()
We don't need to dirty check one-to-one because of how assemble/disassemble is implemented and because a one-to-one association is never dirty
Specified by:
isAlwaysDirtyChecked in interface AssociationType

isDirty

public 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?
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)
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)
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

isNull

public boolean isNull(Object owner,
                      SessionImplementor session)
Overrides:
isNull in interface EntityType

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)
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)
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 session)
            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