Package org.hibernate.type
Class OneToOneType
- java.lang.Object
-
- org.hibernate.type.AbstractType
-
- org.hibernate.type.EntityType
-
- org.hibernate.type.OneToOneType
-
- All Implemented Interfaces:
Serializable,AssociationType,Type
- Direct Known Subclasses:
SpecialOneToOneType
public class OneToOneType extends EntityType
A one-to-one association to an entity- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class org.hibernate.type.EntityType
uniqueKeyPropertyName
-
Fields inherited from class org.hibernate.type.AbstractType
LEGACY_DEFAULT_SIZE, LEGACY_DICTATED_SIZE
-
-
Constructor Summary
Constructors Constructor Description OneToOneType(OneToOneType original, String superTypeEntityName)OneToOneType(TypeConfiguration typeConfiguration, String referencedEntityName, ForeignKeyDirection foreignKeyType, boolean referenceToPrimaryKey, String uniqueKeyPropertyName, boolean lazy, boolean unwrapProxy, String entityName, String propertyName, boolean constrained)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Objectassemble(Serializable oid, SharedSessionContractImplementor session, Object owner)Reconstruct the object from its disassembled state.Serializabledisassemble(Object value, SessionFactoryImplementor sessionFactory)Return a disassembled representation of the object.Serializabledisassemble(Object value, SharedSessionContractImplementor session, Object owner)Return a disassembled representation of the object.intgetColumnSpan(Mapping session)How many columns are used to persist this type?ForeignKeyDirectiongetForeignKeyDirection()Get the foreign key directionality of this associationStringgetPropertyName()int[]getSqlTypeCodes(Mapping session)booleanisAlwaysDirtyChecked()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 dirtybooleanisDirty(Object old, Object current, boolean[] checkable, SharedSessionContractImplementor session)Should the parent be considered dirty, given both the old and current value?booleanisDirty(Object old, Object current, SharedSessionContractImplementor session)Should the parent be considered dirty, given both the old and current value?booleanisModified(Object old, Object current, boolean[] checkable, SharedSessionContractImplementor session)Has the value been modified compared to the current database state? The difference between this and theType.isDirty(java.lang.Object, java.lang.Object, org.hibernate.engine.spi.SharedSessionContractImplementor)methods is that here we need to account for "partially" built values.booleanisNull(Object owner, SharedSessionContractImplementor session)booleanisNullable()The nullability of the property.booleanisOneToOne()Is the association modeled here defined as a 1-1 in the database (physical model)?voidnullSafeSet(PreparedStatement st, Object value, int index, boolean[] settable, SharedSessionContractImplementor session)Bind a value represented by an instance of themapped classto the given JDBCPreparedStatement, ignoring some columns as dictated by thesettableparameter.boolean[]toColumnNullness(Object value, Mapping mapping)Given an instance of the type, return an array ofbooleanvalues indicating which mapped columns would be null.booleanuseLHSPrimaryKey()Is the primary key of the owning entity table to be used in the join?-
Methods inherited from class org.hibernate.type.EntityType
compare, compare, deepCopy, getAssociatedEntityName, getAssociatedEntityName, getAssociatedEntityPersister, getAssociatedJoinable, getHashCode, getIdentifier, getIdentifier, getIdentifierOrUniqueKeyPropertyName, getIdentifierOrUniqueKeyType, getLHSPropertyName, getName, getReturnedClass, getRHSUniqueKeyPropertyName, isAssociationType, isEager, isEntityType, isEqual, isLogicalOneToOne, isMutable, isReferenceToIdentifierProperty, isReferenceToPrimaryKey, isSame, loadByUniqueKey, nullSafeSet, replace, requireIdentifierOrUniqueKeyType, resolve, resolveIdentifier, resolveIdentifier, scope, toLoggableString, toString
-
Methods inherited from class org.hibernate.type.AbstractType
beforeAssemble, getHashCode, isAnyType, isCollectionType, isComponentType, isEqual, replace
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.hibernate.type.Type
beforeAssemble, getHashCode, getReturnedClassName, getTypeForEqualsHashCode, isAnyType, isCollectionType, isComponentType, isEqual, replace
-
-
-
-
Constructor Detail
-
OneToOneType
public OneToOneType(TypeConfiguration typeConfiguration, String referencedEntityName, ForeignKeyDirection foreignKeyType, boolean referenceToPrimaryKey, String uniqueKeyPropertyName, boolean lazy, boolean unwrapProxy, String entityName, String propertyName, boolean constrained)
-
OneToOneType
public OneToOneType(OneToOneType original, String superTypeEntityName)
-
-
Method Detail
-
getPropertyName
public String getPropertyName()
- Overrides:
getPropertyNamein classEntityType
-
isNull
public boolean isNull(Object owner, SharedSessionContractImplementor session)
- Overrides:
isNullin classEntityType
-
getColumnSpan
public int getColumnSpan(Mapping session) throws MappingException
Description copied from interface:TypeHow many columns are used to persist this type?Always the same as
getSqlTypCodes(mapping).length.- Parameters:
session- The mapping object :/- Returns:
- The number of columns
- Throws:
MappingException- Generally indicates an issue accessing the passed mapping object.
-
getSqlTypeCodes
public int[] getSqlTypeCodes(Mapping session) throws MappingException
Description copied from interface:TypeReturn the JDBC types codes as defined byTypesorSqlTypesfor the columns mapped by this type.The number of elements in this array must match the return from
Type.getColumnSpan(org.hibernate.engine.spi.Mapping).- Parameters:
session- The mapping object :/- Returns:
- The JDBC type codes.
- Throws:
MappingException- Generally indicates an issue accessing the passed mapping object.
-
toColumnNullness
public boolean[] toColumnNullness(Object value, Mapping mapping)
Description copied from interface:TypeGiven an instance of the type, return an array ofbooleanvalues indicating which mapped columns would be null.- Parameters:
value- an instance of the typemapping- The mapping abstraction- Returns:
- array indicating column nullness for a value instance
-
nullSafeSet
public void nullSafeSet(PreparedStatement st, Object value, int index, boolean[] settable, SharedSessionContractImplementor session)
Description copied from interface:TypeBind a value represented by an instance of themapped classto the given JDBCPreparedStatement, ignoring some columns as dictated by thesettableparameter. Implementors should handle the possibility of null values. A multi-column type should bind parameters starting fromindex.- Specified by:
nullSafeSetin interfaceType- Overrides:
nullSafeSetin classEntityType- Parameters:
st- The JDBC prepared statement to which to bindvalue- the object to writeindex- starting parameter bind indexsettable- an array indicating which columns to bind/ignoresession- The originating session
-
isOneToOne
public boolean isOneToOne()
Description copied from class:EntityTypeIs the association modeled here defined as a 1-1 in the database (physical model)?- Specified by:
isOneToOnein classEntityType- Returns:
- True if a 1-1 in the database; false otherwise.
-
isDirty
public boolean isDirty(Object old, Object current, SharedSessionContractImplementor session)
Description copied from interface:TypeShould the parent be considered dirty, given both the old and current value?- Specified by:
isDirtyin interfaceType- Overrides:
isDirtyin classAbstractType- Parameters:
old- the old valuecurrent- the current valuesession- The session from which the request originated.- Returns:
- true if the field is dirty
-
isDirty
public boolean isDirty(Object old, Object current, boolean[] checkable, SharedSessionContractImplementor session)
Description copied from interface:TypeShould the parent be considered dirty, given both the old and current value?- Parameters:
old- the old valuecurrent- the current valuecheckable- An array of booleans indicating which columns making up the value are actually checkablesession- The session from which the request originated.- Returns:
- true if the field is dirty
-
isModified
public boolean isModified(Object old, Object current, boolean[] checkable, SharedSessionContractImplementor session)
Description copied from interface:TypeHas the value been modified compared to the current database state? The difference between this and theType.isDirty(java.lang.Object, java.lang.Object, org.hibernate.engine.spi.SharedSessionContractImplementor)methods is that here we need to account for "partially" built values. This is really only an issue with association types. For most type implementations it is enough to simply delegate toType.isDirty(java.lang.Object, java.lang.Object, org.hibernate.engine.spi.SharedSessionContractImplementor).- Specified by:
isModifiedin interfaceType- Overrides:
isModifiedin classAbstractType- Parameters:
old- the database state, in a "hydrated" form, with identifiers unresolvedcurrent- the current state of the objectcheckable- which columns are actually checkablesession- The session from which the request originated.- Returns:
- true if the field has been modified
-
getForeignKeyDirection
public ForeignKeyDirection getForeignKeyDirection()
Description copied from interface:AssociationTypeGet the foreign key directionality of this association
-
isNullable
public boolean isNullable()
Description copied from class:EntityTypeThe nullability of the property.- Specified by:
isNullablein classEntityType- Returns:
- The nullability of the property.
-
useLHSPrimaryKey
public boolean useLHSPrimaryKey()
Description copied from interface:AssociationTypeIs the primary key of the owning entity table to be used in the join?
-
disassemble
public Serializable disassemble(Object value, SharedSessionContractImplementor session, Object owner) throws HibernateException
Description copied from interface:TypeReturn a disassembled representation of the object. This is the representation that is stored in the second-level cache.A reference to an associated entity should be disassembled to its primary key value.
- Specified by:
disassemblein interfaceType- Overrides:
disassemblein classAbstractType- Parameters:
value- the value to cachesession- the originating sessionowner- optional parent entity object (needed for collections)- Returns:
- the disassembled, deep cloned state
- Throws:
HibernateException- An error from Hibernate
-
disassemble
public Serializable disassemble(Object value, SessionFactoryImplementor sessionFactory) throws HibernateException
Description copied from interface:TypeReturn a disassembled representation of the object. This is the representation that is stored in the second-level cache.A reference to an associated entity should be disassembled to its primary key value.
A high-quality implementation of this method should ensure that:
Objects.equals(disassemble(x,s), disassemble(y,s))== isEqual(x,y,sf)and that:
Objects.equals(x, assemble(disassemble(x,s),s,o))That is, the implementation must be consistent with
Type.isEqual(Object, Object, SessionFactoryImplementor)and withType.assemble(Serializable, SharedSessionContractImplementor, Object).- Specified by:
disassemblein interfaceType- Overrides:
disassemblein classAbstractType- Parameters:
value- the value to cachesessionFactory- the session factory- Returns:
- the disassembled, deep cloned state
- Throws:
HibernateException- An error from Hibernate
-
assemble
public Object assemble(Serializable oid, SharedSessionContractImplementor session, Object owner) throws HibernateException
Description copied from interface:TypeReconstruct the object from its disassembled state. This function is the inverse ofType.disassemble(Object, SharedSessionContractImplementor, Object).- Specified by:
assemblein interfaceType- Overrides:
assemblein classAbstractType- Parameters:
oid- the disassembled state from the cachesession- the originating sessionowner- the parent entity object- Returns:
- the (re)assembled object
- Throws:
HibernateException- An error from Hibernate
-
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
-
-