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,QueryParameterJavaObjectType,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.
- API Note:
- This interface—which has existed since the very earliest days of Hibernate—used
to be an important API. In modern versions of Hibernate its role has evolved, and it is no
longer considered an API, though it's still a very important SPI. Application programs should
avoid direct use of this interface where possible. In many cases,
JavaTypeorJdbcTypemay be used instead.
-
Method Summary
Modifier and TypeMethodDescription@Nullable Objectassemble(@Nullable Serializable 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 anymoreintPerform aComparator-style comparison of the given values.intcompare(@Nullable Object x, @Nullable Object y, SessionFactoryImplementor sessionFactory) @Nullable ObjectdeepCopy(@Nullable Object value, SessionFactoryImplementor factory) Return a deep copy of the persistent state, stopping at entities and at collections.@Nullable Serializabledisassemble(@Nullable Object value, @Nullable SharedSessionContractImplementor session, @Nullable Object owner) Return a disassembled representation of the object.default @Nullable Serializabledisassemble(@Nullable Object value, SessionFactoryImplementor sessionFactory) Return a disassembled representation of the object.intgetColumnSpan(MappingContext mappingContext) How many columns are used to persist this type?intGet a hash code, consistent with persistence "equality".intgetHashCode(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 StringThe qualified name of the class handled by this type.int[]getSqlTypeCodes(MappingContext mappingContext) default @Nullable TypeThe type to use forequals()andhashCode()computation.booleanReturn true if the implementation is castable toAnyType.booleanReturn true if the implementation is castable toAssociationType.booleanReturn true if the implementation is castable toCollectionType.booleanReturn true if the implementation is castable toCompositeType.booleanisDirty(@Nullable Object oldState, @Nullable Object currentState, boolean[] checkable, SharedSessionContractImplementor session) Should the parent be considered dirty, given both the old and current value?booleanisDirty(@Nullable Object old, @Nullable Object current, SharedSessionContractImplementor session) Should the parent be considered dirty, given both the old and current value?booleanReturn true if the implementation is castable toEntityType.booleanCompare two instances of the class mapped by this type for persistence "equality", that is, equality of persistent state.booleanisEqual(@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.booleanisModified(@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.booleanAre objects of this type mutable with respect to the referencing object? Entities and collections are considered immutable because they manage their own internal state.booleanCompare 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, @Nullable 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.voidnullSafeSet(PreparedStatement st, @Nullable Object 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.@Nullable Objectreplace(@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 Objectreplace(@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, MappingContext mappingContext) Given an instance of the type, return an array ofbooleanvalues 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
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
How many columns are used to persist this type?Always the same as
getSqlTypCodes(mappingContext).length.- Parameters:
mappingContext- The mapping Context objectMappingContext- Returns:
- The number of columns
- Throws:
MappingException- Generally indicates an issue accessing the passed mappingContext object.
-
getSqlTypeCodes
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.type.MappingContext).- Parameters:
mappingContext- The mapping contextMappingContext:/- 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
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(@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
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
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 ofbooleanvalues indicating which mapped columns would be null.- Parameters:
value- an instance of the typemappingContext- The mapping contextMappingContext- Returns:
- array indicating column nullness for a value instance
-