Interface Type
- All Superinterfaces:
Serializable
- All Known Subinterfaces:
AdjustableBasicType<J>,AssociationType,BasicPluralType<C,E>,BasicType<T>,CompositeType,CompositeTypeImplementor,ConvertedBasicType<J>,DiscriminatorType<O>
- All Known Implementing Classes:
AbstractSingleColumnStandardBasicType,AbstractStandardBasicType,AbstractType,AnyType,ArrayType,BagType,BasicArrayType,BasicCollectionType,BasicTypeImpl,BottomType,CollectionType,ComponentType,ConvertedBasicArrayType,ConvertedBasicCollectionType,ConvertedBasicTypeImpl,CustomCollectionType,CustomMutabilityConvertedBasicTypeImpl,CustomMutabilityConvertedPrimitiveBasicTypeImpl,CustomType,DiscriminatorType,DiscriminatorTypeImpl,EmbeddedComponentType,EntityType,IdentifierBagType,ImmutableNamedBasicTypeImpl,JavaObjectType,ListType,ManyToOneType,MapType,MetaType,NamedBasicTypeImpl,NullType,OneToOneType,OrderedMapType,OrderedSetType,ProcessorSessionFactory.Component,QueryParameterJavaObjectType,SerializableToBlobType,SerializableType,SetType,SortedMapType,SortedSetType,SpecialOneToOneType,StandardBasicTypeTemplate,UserComponentType
@Internalpublic interfaceTypeextendsSerializable
Defines a mapping between a Java type and one or more JDBCtypes, as well as describing the in-memory semantics of the given Java type, including:- how to compare values and check for "dirtiness",
- how to clone values, and
- how to assemble/disassemble values for storage in the second-level cache.
An application-defined custom types could, in principle, implement this interface directly, but it's safer to implement the more stable interface
UserType.An implementation of this interface must certainly be thread-safe. Ideally, it should also be immutable.
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description @NullableObjectassemble(@NullableSerializable cached,SharedSessionContractImplementor session,Object owner)Reconstruct the object from its disassembled state.voidbeforeAssemble(Serializable cached,SharedSessionContractImplementor session)Deprecated, for removal: This API element is subject to removal in a future version.Is not called anymoreintcompare(@NullableObject x, @NullableObject y)Perform aComparator-style comparison of the given values.intcompare(@NullableObject x, @NullableObject y,SessionFactoryImplementor sessionFactory)@NullableObjectdeepCopy(@NullableObject value,SessionFactoryImplementor factory)Return a deep copy of the persistent state, stopping at entities and at collections.@NullableSerializabledisassemble(@NullableObject value, @NullableSharedSessionContractImplementor session, @NullableObject owner)Return a disassembled representation of the object.default @NullableSerializabledisassemble(@NullableObject value,SessionFactoryImplementor sessionFactory)Return a disassembled representation of the object.intgetColumnSpan(Mapping mapping)How many columns are used to persist this type?intgetHashCode(Object x)Get a hash code, consistent with persistence "equality".intgetHashCode(Object x,SessionFactoryImplementor factory)Get a hash code, consistent with persistence "equality".StringgetName()Returns the abbreviated name of the type.Class<?>getReturnedClass()The class handled by this type.defaultStringgetReturnedClassName()The qualified name of the class handled by this type.int[]getSqlTypeCodes(Mapping mapping)default @NullableTypegetTypeForEqualsHashCode()The type to use forequals()andhashCode()computation.booleanisAnyType()Return true if the implementation is castable toAnyType.booleanisAssociationType()Return true if the implementation is castable toAssociationType.booleanisCollectionType()Return true if the implementation is castable toCollectionType.booleanisComponentType()Return true if the implementation is castable toCompositeType.booleanisDirty(@NullableObject oldState, @NullableObject currentState, boolean[] checkable,SharedSessionContractImplementor session)Should the parent be considered dirty, given both the old and current value?booleanisDirty(@NullableObject old, @NullableObject current,SharedSessionContractImplementor session)Should the parent be considered dirty, given both the old and current value?booleanisEntityType()Return true if the implementation is castable toEntityType.booleanisEqual(@NullableObject x, @NullableObject y)Compare two instances of the class mapped by this type for persistence "equality", that is, equality of persistent state.booleanisEqual(@NullableObject x, @NullableObject y,SessionFactoryImplementor factory)Compare two instances of the class mapped by this type for persistence "equality", that is, equality of persistent state.booleanisModified(@NullableObject dbState, @NullableObject currentState, boolean[] checkable,SharedSessionContractImplementor session)Has the value been modified compared to the current database state? The difference between this and theisDirty(java.lang.Object, java.lang.Object, org.hibernate.engine.spi.SharedSessionContractImplementor)methods is that here we need to account for "partially" built values.booleanisMutable()Are objects of this type mutable with respect to the referencing object? Entities and collections are considered immutable because they manage their own internal state.booleanisSame(@NullableObject x, @NullableObject y)Compare two instances of the class mapped by this type for persistence "equality", that is, equality of persistent state, taking a shortcut for entity references.voidnullSafeSet(PreparedStatement st, @NullableObject 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.voidnullSafeSet(PreparedStatement st, @NullableObject value, int index,SharedSessionContractImplementor session)Bind a value represented by an instance of themapped classto the given JDBCPreparedStatement, ignoring some columns as dictated by thesettableparameter.@NullableObjectreplace(@NullableObject original, @NullableObject target,SharedSessionContractImplementor session,Object owner,Map<Object,Object> copyCache)During merge, replace the existing (target) value in the entity we are merging to with a new (original) value from the detached entity we are merging.@NullableObjectreplace(@NullableObject original, @NullableObject target,SharedSessionContractImplementor session,Object owner,Map<Object,Object> copyCache,ForeignKeyDirection foreignKeyDirection)During merge, replace the existing (target) value in the entity we are merging to with a new (original) value from the detached entity we are merging.boolean[]toColumnNullness(@NullableObject value,Mapping mapping)Given an instance of the type, return an array ofbooleanvalues indicating which mapped columns would be null.StringtoLoggableString(@NullableObject value,SessionFactoryImplementor factory)Generate a representation of the given value for logging purposes.
Method Detail
isAssociationType
boolean isAssociationType()
Return true if the implementation is castable toAssociationType. This does not necessarily imply that the type actually represents an association. Shortcut fortype instanceof AssociationType.- Returns:
- True if this type is also an
AssociationTypeimplementor; false otherwise.
isCollectionType
boolean isCollectionType()
Return true if the implementation is castable toCollectionType. Shortcut fortype instanceof CollectionTypeA
CollectionTypeis additionally anAssociationType; so if this method returns true,isAssociationType()should also return true.- Returns:
- True if this type is also a
CollectionTypeimplementor; false otherwise.
isEntityType
boolean isEntityType()
Return true if the implementation is castable toEntityType. Shortcut fortype instanceof EntityType.An
EntityTypeis additionally anAssociationType; so if this method returns true,isAssociationType()should also return true.- Returns:
- True if this type is also an
EntityTypeimplementor; false otherwise.
isAnyType
boolean isAnyType()
Return true if the implementation is castable toAnyType. Shortcut fortype instanceof AnyType.An
AnyTypeis additionally anAssociationType; so if this method returns true, thenisAssociationType()should also return true.- Returns:
- True if this type is also an
AnyTypeimplementor; false otherwise.
isComponentType
boolean isComponentType()
Return true if the implementation is castable toCompositeType. Shortcut fortype instanceof CompositeType.A component type may own collections or associations and hence must provide certain extra functionality.
- Returns:
- True if this type is also a
CompositeTypeimplementor; false otherwise.
getColumnSpan
int getColumnSpan(Mapping mapping) throwsMappingException
How many columns are used to persist this type?Always the same as
getSqlTypCodes(mapping).length.- Parameters:
mapping- The mapping object :/- Returns:
- The number of columns
- Throws:
MappingException- Generally indicates an issue accessing the passed mapping object.
getSqlTypeCodes
int[] getSqlTypeCodes(Mapping mapping) throwsMappingException
Return 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
getColumnSpan(org.hibernate.engine.spi.Mapping).- Parameters:
mapping- The mapping object :/- Returns:
- The JDBC type codes.
- Throws:
MappingException- Generally indicates an issue accessing the passed mapping object.
getReturnedClass
Class<?> getReturnedClass()
The class handled by this type.- Returns:
- The Java class handled by this type.
getReturnedClassName
default String getReturnedClassName()
The qualified name of the class handled by this type.- Returns:
- The qualified Java class name.
- Since:
- 6.5
isSame
boolean isSame(@NullableObject x, @NullableObject y) throwsHibernateException
Compare two instances of the class mapped by this type for persistence "equality", that is, equality of persistent state, taking a shortcut for entity references.For most types this should boil down to anequality comparison of the given values, and it's reasonable to simply delegate to
isEqual(Object, Object). But for associations the semantics are a bit different.- Parameters:
x- The first valuey- The second value- Returns:
- True if there are considered the same (see discussion above).
- Throws:
HibernateException- A problem occurred performing the comparison
isEqual
boolean isEqual(@NullableObject x, @NullableObject y) throwsHibernateException
Compare two instances of the class mapped by this type for persistence "equality", that is, equality of persistent state. For most types this could simply delegate toequals().This should always equate to some form of comparison of the value's internal state. As an example, for Java's
Dateclass, the comparison should be of its internal state, but based only on the specific part which is persistent (the timestamp, date, or time).- Parameters:
x- The first valuey- The second value- Returns:
- True if there are considered equal (see discussion above).
- Throws:
HibernateException- A problem occurred performing the comparison
isEqual
boolean isEqual(@NullableObject x, @NullableObject y,SessionFactoryImplementor factory) throwsHibernateException
Compare two instances of the class mapped by this type for persistence "equality", that is, equality of persistent state. For most types this could simply delegate toisEqual(Object, Object).This should always equate to some form of comparison of the value's internal state. As an example, for Java's
Dateclass, the comparison should be of its internal state, but based only on the specific part which is persistent (the timestamp, date, or time).- Parameters:
x- The first valuey- The second valuefactory- The session factory- Returns:
- True if there are considered equal (see discussion above).
- Throws:
HibernateException- A problem occurred performing the comparison
getHashCode
int getHashCode(Object x) throwsHibernateException
Get a hash code, consistent with persistence "equality". For most types this could simply delegate to the given value'shashCode.- Parameters:
x- The value for which to retrieve a hash code- Returns:
- The hash code
- Throws:
HibernateException- A problem occurred calculating the hash code
getHashCode
int getHashCode(Object x,SessionFactoryImplementor factory) throwsHibernateException
Get a hash code, consistent with persistence "equality". For most types this could simply delegate togetHashCode(Object).- Parameters:
x- The value for which to retrieve a hash codefactory- The session factory- Returns:
- The hash code
- Throws:
HibernateException- A problem occurred calculating the hash code
getTypeForEqualsHashCode
default @NullableType getTypeForEqualsHashCode()
The type to use forequals()andhashCode()computation. Whennull, useObject.equals(Object)andObject.hashCode(). This is useful to avoid mega-morphic callsites.
compare
int compare(@NullableObject x, @NullableObject y)
Perform aComparator-style comparison of the given values.- Parameters:
x- The first valuey- The second value- Returns:
- The comparison result.
- See Also:
Comparator.compare(Object, Object)
compare
int compare(@NullableObject x, @NullableObject y,SessionFactoryImplementor sessionFactory)
isDirty
boolean isDirty(@NullableObject old, @NullableObject current,SharedSessionContractImplementor session) throwsHibernateException
Should the parent be considered dirty, given both the old and current value?- Parameters:
old- the old valuecurrent- the current valuesession- The session from which the request originated.- Returns:
- true if the field is dirty
- Throws:
HibernateException- A problem occurred performing the checking
isDirty
boolean isDirty(@NullableObject oldState, @NullableObject currentState, boolean[] checkable,SharedSessionContractImplementor session) throwsHibernateException
Should the parent be considered dirty, given both the old and current value?- Parameters:
oldState- the old valuecurrentState- 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
- Throws:
HibernateException- A problem occurred performing the checking
isModified
boolean isModified(@NullableObject dbState, @NullableObject currentState, boolean[] checkable,SharedSessionContractImplementor session) throwsHibernateException
Has the value been modified compared to the current database state? The difference between this and theisDirty(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 toisDirty(java.lang.Object, java.lang.Object, org.hibernate.engine.spi.SharedSessionContractImplementor).- Parameters:
dbState- the database state, in a "hydrated" form, with identifiers unresolvedcurrentState- 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
- Throws:
HibernateException- A problem occurred performing the checking
nullSafeSet
void nullSafeSet(PreparedStatement st, @NullableObject value, int index, boolean[] settable,SharedSessionContractImplementor session) throwsHibernateException,SQLException
Bind 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.- 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- Throws:
HibernateException- An error from HibernateSQLException- An error from the JDBC driver
nullSafeSet
void nullSafeSet(PreparedStatement st, @NullableObject value, int index,SharedSessionContractImplementor session) throwsHibernateException,SQLException
Bind 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.- Parameters:
st- The JDBC prepared statement to which to bindvalue- the object to writeindex- starting parameter bind indexsession- The originating session- Throws:
HibernateException- An error from HibernateSQLException- An error from the JDBC driver
toLoggableString
String toLoggableString(@NullableObject value,SessionFactoryImplementor factory) throwsHibernateException
Generate a representation of the given value for logging purposes.- Parameters:
value- The value to be loggedfactory- The session factory- Returns:
- The loggable representation
- Throws:
HibernateException- An error from Hibernate
getName
String getName()
Returns the abbreviated name of the type.- Returns:
- the Hibernate type name
deepCopy
@NullableObject deepCopy(@NullableObject value,SessionFactoryImplementor factory) throwsHibernateException
Return a deep copy of the persistent state, stopping at entities and at collections.- Parameters:
value- The value to be copiedfactory- The session factory- Returns:
- The deep copy
- Throws:
HibernateException- An error from Hibernate
isMutable
boolean isMutable()
Are objects of this type mutable with respect to the referencing object? Entities and collections are considered immutable because they manage their own internal state.- Returns:
- boolean
disassemble
default @NullableSerializable disassemble(@NullableObject value,SessionFactoryImplementor sessionFactory) throwsHibernateException
Return 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
isEqual(Object, Object, SessionFactoryImplementor)and withassemble(Serializable, SharedSessionContractImplementor, Object).- Parameters:
value- the value to cachesessionFactory- the session factory- Returns:
- the disassembled, deep cloned state
- Throws:
HibernateException- An error from Hibernate
disassemble
@NullableSerializable disassemble(@NullableObject value, @NullableSharedSessionContractImplementor session, @NullableObject owner) throwsHibernateException
Return 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.
- 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
assemble
@NullableObject assemble(@NullableSerializable cached,SharedSessionContractImplementor session,Object owner) throwsHibernateException
Reconstruct the object from its disassembled state. This function is the inverse ofdisassemble(Object, SharedSessionContractImplementor, Object).- Parameters:
cached- the disassembled state from the cachesession- the originating sessionowner- the parent entity object- Returns:
- the (re)assembled object
- Throws:
HibernateException- An error from Hibernate
beforeAssemble
@Deprecated(forRemoval=true,since="6.6")void beforeAssemble(Serializable cached,SharedSessionContractImplementor session)
Deprecated, for removal: This API element is subject to removal in a future version.Is not called anymoreCalled before assembling a query result set from the query cache, to allow batch fetching of entities missing from the second-level cache.- Parameters:
cached- The keysession- The originating session
replace
@NullableObject replace(@NullableObject original, @NullableObject target,SharedSessionContractImplementor session,Object owner,Map<Object,Object> copyCache) throwsHibernateException
During merge, replace the existing (target) value in the entity we are merging to with a new (original) value from the detached entity we are merging. For immutable objects, or null values, it is safe to simply return the first parameter. For mutable objects, it is safe to return a copy of the first parameter. For objects with component values, it might make sense to recursively replace component values.- Parameters:
original- the value from the detached entity being mergedtarget- the value in the managed entitysession- The originating sessionowner- The owner of the valuecopyCache- The cache of already copied/replaced values- Returns:
- the value to be merged
- Throws:
HibernateException- An error from Hibernate
replace
@NullableObject replace(@NullableObject original, @NullableObject target,SharedSessionContractImplementor session,Object owner,Map<Object,Object> copyCache,ForeignKeyDirection foreignKeyDirection) throwsHibernateException
During merge, replace the existing (target) value in the entity we are merging to with a new (original) value from the detached entity we are merging. For immutable objects, or null values, it is safe to simply return the first parameter. For mutable objects, it is safe to return a copy of the first parameter. For objects with component values, it might make sense to recursively replace component values.- Parameters:
original- the value from the detached entity being mergedtarget- the value in the managed entitysession- The originating sessionowner- The owner of the valuecopyCache- The cache of already copied/replaced valuesforeignKeyDirection- For associations, which direction does the foreign key point?- Returns:
- the value to be merged
- Throws:
HibernateException- An error from Hibernate
toColumnNullness
boolean[] toColumnNullness(@NullableObject value,Mapping mapping)
Given 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