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
- 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
Modifier and TypeMethodDescription@Nullable Object
assemble
(@Nullable Serializable cached, SharedSessionContractImplementor session, Object owner) Reconstruct the object from its disassembled state.void
beforeAssemble
(Serializable cached, SharedSessionContractImplementor session) Deprecated, for removal: This API element is subject to removal in a future version.Is not called anymoreint
Perform aComparator
-style comparison of the given values.int
compare
(@Nullable Object x, @Nullable Object y, SessionFactoryImplementor sessionFactory) @Nullable Object
deepCopy
(@Nullable Object value, SessionFactoryImplementor factory) Return a deep copy of the persistent state, stopping at entities and at collections.@Nullable Serializable
disassemble
(@Nullable Object value, @Nullable SharedSessionContractImplementor session, @Nullable Object owner) Return a disassembled representation of the object.default @Nullable Serializable
disassemble
(@Nullable Object value, SessionFactoryImplementor sessionFactory) Return a disassembled representation of the object.int
getColumnSpan
(Mapping mapping) How many columns are used to persist this type?int
Get a hash code, consistent with persistence "equality".int
getHashCode
(Object x, SessionFactoryImplementor factory) Get a hash code, consistent with persistence "equality".getName()
Returns the abbreviated name of the type.Class<?>
The class handled by this type.default String
The qualified name of the class handled by this type.int[]
getSqlTypeCodes
(Mapping mapping) default @Nullable Type
The type to use forequals()
andhashCode()
computation.boolean
Return true if the implementation is castable toAnyType
.boolean
Return true if the implementation is castable toAssociationType
.boolean
Return true if the implementation is castable toCollectionType
.boolean
Return true if the implementation is castable toCompositeType
.boolean
isDirty
(@Nullable Object oldState, @Nullable Object currentState, boolean[] checkable, SharedSessionContractImplementor session) Should the parent be considered dirty, given both the old and current value?boolean
isDirty
(@Nullable Object old, @Nullable Object current, SharedSessionContractImplementor session) Should the parent be considered dirty, given both the old and current value?boolean
Return true if the implementation is castable toEntityType
.boolean
Compare two instances of the class mapped by this type for persistence "equality", that is, equality of persistent state.boolean
isEqual
(@Nullable Object x, @Nullable Object y, SessionFactoryImplementor factory) Compare two instances of the class mapped by this type for persistence "equality", that is, equality of persistent state.boolean
isModified
(@Nullable Object dbState, @Nullable Object 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.boolean
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.boolean
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.void
nullSafeSet
(PreparedStatement st, @Nullable Object value, int index, boolean[] settable, SharedSessionContractImplementor session) Bind a value represented by an instance of themapped class
to the given JDBCPreparedStatement
, ignoring some columns as dictated by thesettable
parameter.void
nullSafeSet
(PreparedStatement st, @Nullable Object value, int index, SharedSessionContractImplementor session) Bind a value represented by an instance of themapped class
to the given JDBCPreparedStatement
, ignoring some columns as dictated by thesettable
parameter.@Nullable Object
replace
(@Nullable Object original, @Nullable Object 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.@Nullable Object
replace
(@Nullable Object original, @Nullable Object 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
(@Nullable Object value, Mapping mapping) Given an instance of the type, return an array ofboolean
values indicating which mapped columns would be null.toLoggableString
(@Nullable Object value, SessionFactoryImplementor factory) Generate a representation of the given value for logging purposes.
-
Method Details
-
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
AssociationType
implementor; false otherwise.
-
isCollectionType
boolean isCollectionType()Return true if the implementation is castable toCollectionType
. Shortcut fortype instanceof CollectionType
A
CollectionType
is additionally anAssociationType
; so if this method returns true,isAssociationType()
should also return true.- Returns:
- True if this type is also a
CollectionType
implementor; false otherwise.
-
isEntityType
boolean isEntityType()Return true if the implementation is castable toEntityType
. Shortcut fortype instanceof EntityType
.An
EntityType
is additionally anAssociationType
; so if this method returns true,isAssociationType()
should also return true.- Returns:
- True if this type is also an
EntityType
implementor; false otherwise.
-
isAnyType
boolean isAnyType()Return true if the implementation is castable toAnyType
. Shortcut fortype instanceof AnyType
.An
AnyType
is additionally anAssociationType
; so if this method returns true, thenisAssociationType()
should also return true.- Returns:
- True if this type is also an
AnyType
implementor; 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
CompositeType
implementor; false otherwise.
-
getColumnSpan
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
Return the JDBC types codes as defined byTypes
orSqlTypes
for 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
The qualified name of the class handled by this type.- Returns:
- The qualified Java class name.
- Since:
- 6.5
-
isSame
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 an equality 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
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
Date
class, 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(@Nullable Object x, @Nullable Object y, SessionFactoryImplementor factory) throws HibernateException 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
Date
class, 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
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
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
The type to use forequals()
andhashCode()
computation. Whennull
, useObject.equals(Object)
andObject.hashCode()
. This is useful to avoid mega-morphic callsites. -
compare
Perform aComparator
-style comparison of the given values.- Parameters:
x
- The first valuey
- The second value- Returns:
- The comparison result.
- See Also:
-
compare
-
toLoggableString
String toLoggableString(@Nullable Object value, SessionFactoryImplementor factory) throws HibernateException 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
@Nullable Object deepCopy(@Nullable Object value, SessionFactoryImplementor factory) throws HibernateException 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 @Nullable Serializable disassemble(@Nullable Object value, SessionFactoryImplementor sessionFactory) throws HibernateException 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
-
toColumnNullness
Given an instance of the type, return an array ofboolean
values 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
-