Package org.hibernate.type
Type
is a strategy for mapping a Java
property type to a JDBC type or types. Every persistent attribute of an entity
or embeddable object has a Type
, even attributes which represent
associations or hold references to embedded objects.
On the other hand, in modern Hibernate, Type
itself is of receding
importance to application developers, though it remains a very important
internal abstraction.
Basic types
For basic types, we prefer to model the type mapping in terms the combination of:
A JdbcType
is able to read and write a single Java type to one, or
sometimes several, JDBC types.
A JavaType
is able to determine if an attribute of a given Java type is
dirty, and then convert it to one of several other equivalent Java representations
at the request of its partner JdbcType
.
For example, if an entity attribute of Java type BigInteger
is mapped to
the JDBC type Types.VARCHAR
, the
VarcharJdbcType
will ask its
BigIntegerJavaType
to convert instances
of BigInteger
to and from String
when writing to and reading from
JDBC statements and result sets.
An important point is that the set of available JavaType
s and of available
JdbcType
s is not fixed—a TypeConfiguration
is customizable during the
bootstrap process.
This approach provides quite some flexibility in allowing a given Java type to
map to a range of JDBC types. However, when the built-in conversions don't handle
a particular mapping, a
converter
may assist in the conversion process. For example, a JPA
AttributeConverter
might be provided.
A JavaType
comes with a built-in
MutabilityPlan
, but this may be
overridden when types are composed.
See org.hibernate.annotations
for information on how to influence basic
type mappings using annotations.
Custom types
The packageorg.hibernate.usertype
provides a way for application developers
to define new types without being exposed to the full complexity of the Type
framework defined in this package.
- A
UserType
may be used to define single-column type mappings, and thus competes with the "compositional" approach to basic type mappings described above. - On the other hand, a
CompositeUserType
defines a way to handle multi-column type mappings, and is a much more flexible form ofEmbeddable
object mapping.
Built-in converters for boolean mappings
In older versions of Hibernate there were dedicatedType
s mapping Java
boolean
to char(1)
or integer
database columns. These
have now been replaced by the converters:
TrueFalseConverter
, which encodes a boolean value as'T'
or'F'
,YesNoConverter
, which encodes a boolean value as'Y'
or'N'
, andNumericBooleanConverter
, which encodes a boolean value as1
or0
.
These converters may be applied, as usual, using the JPA-defined
Converter
annotation.
-
ClassDescriptionTODO : javadocConvenience base class for
BasicType
implementations.Abstract superclass of the built-inType
hierarchy.Extension contract forBasicType
implementations which understand how to adjust themselves relative to where/how they're used by, for example, accounting for LOB, nationalized, primitive/wrapper, etc.Handles "any" mappingsUsed to externalize discrimination per a given identifier.A type for persistent arrays.A type that represents some kind of association between entities.BasicArrayType<T,E> A type that maps betweenARRAY
andT[]
A type that maps betweenARRAY
andCollection<T>
BasicPluralType<C,E> A basic plural type.BasicType<T>Marker interface for basic types.A basic type reference.A registry ofBasicType
instancesA type that is assignable to every non-primitive type, that is, the type ofnull
.A type that handles HibernatePersistentCollection
s (including arrays).Handles embedded mappings.Represents a composite type, a type which itself has typed attributes.ConvertedBasicArrayType<T,S, E> Given aBasicValueConverter
for an array type,A converted basic array type.Extension for implementations ofBasicType
which have an implied conversion.A custom type for mapping user-written classes that implementPersistentCollection
CustomType<J>Base for types which map associations to persistent entities.Deprecated, for removal: This API element is subject to removal in a future version.Use the built-in support for enumsRepresents directionality of the foreign key constraintA many-to-one association to an entity.Deprecated, for removal: This API element is subject to removal in a future version.The functionality of MetaType,DiscriminatorType
andDiscriminatorMetadata
have been consolidated intoEntityDiscriminatorMapping
andDiscriminatorConverter
Handles conversion to/fromBoolean
as0
(false) or1
(true)A one-to-one association to an entityA specialization of the map type, with (resultset-based) ordering.A specialization of the set type, with (resultset-based) ordering.OptionalType
contract for implementations that are aware of how to extract values from store procedure OUT/INOUT parameters.OptionalType
contract for implementations enabled to set store procedure OUT/INOUT parameters values by name.SerializableToBlobType<T extends Serializable>SerializableType<T extends Serializable>A type that maps between aVARBINARY
andSerializable
classes.Thrown when a property cannot be serialized/deserializedA one-to-one association that maps to specific formula(s) instead of the primary key column of the owning entity.Defines a list of constant type codes used to identify generic SQL types.References to commonBasicTypeReference
instancesA BasicType adapter targeting partial portability to 6.0's type system changes.Marker for Hibernate defined converters of Boolean-typed domain valuesStandardConverter<O,R> Marker for Hibernate supplied converter classes.Handles conversion to/fromBoolean
as'T'
or'F'
Defines a mapping between a Java type and one or more JDBC types, 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.Certain operations for working with arrays of property values.HandlesCompositeUserType
s.Possible options for how to handleByte[]
andCharacter[]
basic mappings encountered in the application domain model.Handles conversion to/fromBoolean
as'Y'
or'N'