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.
-
Interface Summary Interface Description AdjustableBasicType<J> 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.AssociationType A type that represents some kind of association between entities.BasicPluralType<C,E> A basic plural type.BasicType<T> Marker interface for basic types.CompositeType Represents a composite type, a type which itself has typed attributes.ConvertedBasicType<J> Extension for implementations ofBasicType
which have an implied conversion.ProcedureParameterExtractionAware<T> OptionalType
contract for implementations that are aware of how to extract values from store procedure OUT/INOUT parameters.ProcedureParameterNamedBinder<J> OptionalType
contract for implementations enabled to set store procedure OUT/INOUT parameters values by name.StandardBooleanConverter<R> Marker for Hibernate defined converters of Boolean-typed domain valuesStandardConverter<O,R> Marker for Hibernate supplied converter classes.Type 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. -
Class Summary Class Description AbstractSingleColumnStandardBasicType<T> TODO : javadocAbstractStandardBasicType<T> Convenience base class forBasicType
implementations.AbstractType Abstract superclass of the built-inType
hierarchy.AnyType Handles "any" mappingsAnyType.ObjectTypeCacheEntry Used to externalize discrimination per a given identifier.ArrayType A type for persistent arrays.BagType BasicArrayType<T,E> A type that maps betweenARRAY
andT[]
BasicCollectionType<C extends Collection<E>,E> A type that maps betweenARRAY
andCollection<T>
BasicTypeReference<T> A basic type reference.BasicTypeRegistry A registry ofBasicType
instancesBottomType A type that is assignable to every non-primitive type, that is, the type ofnull
.CharBooleanConverter CollectionType A type that handles HibernatePersistentCollection
s (including arrays).ComponentType Handles embedded mappings.ConvertedBasicArrayType<T,S,E> Given aBasicValueConverter
for an array type,ConvertedBasicCollectionType<C extends Collection<E>,E> A converted basic array type.CustomCollectionType A custom type for mapping user-written classes that implementPersistentCollection
CustomType<J> EmbeddedComponentType EntityType Base for types which map associations to persistent entities.EnumType<T extends Enum<T>> Deprecated, for removal: This API element is subject to removal in a future version. Use the built-in support for enumsIdentifierBagType JavaObjectType ListType ManyToOneType A many-to-one association to an entity.MapType MetaType 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
NullType NumericBooleanConverter Handles conversion to/fromBoolean
as0
(false) or1
(true)OneToOneType A one-to-one association to an entityOrderedMapType A specialization of the map type, with (resultset-based) ordering.OrderedSetType A specialization of the set type, with (resultset-based) ordering.QueryParameterJavaObjectType SerializableToBlobType<T extends Serializable> SerializableType<T extends Serializable> A type that maps between aVARBINARY
andSerializable
classes.SetType SortedMapType SortedSetType SpecialOneToOneType A one-to-one association that maps to specific formula(s) instead of the primary key column of the owning entity.SqlTypes Defines a list of constant type codes used to identify generic SQL types.StandardBasicTypes References to commonBasicTypeReference
instancesStandardBasicTypeTemplate<J> A BasicType adapter targeting partial portability to 6.0's type system changes.TrueFalseConverter Handles conversion to/fromBoolean
as'T'
or'F'
TypeHelper Certain operations for working with arrays of property values.UserComponentType<T> HandlesCompositeUserType
s.YesNoConverter Handles conversion to/fromBoolean
as'Y'
or'N'
-
Enum Summary Enum Description ForeignKeyDirection Represents directionality of the foreign key constraintWrapperArrayHandling Possible options for how to handleByte[]
andCharacter[]
basic mappings encountered in the application domain model. -
Exception Summary Exception Description SerializationException Thrown when a property cannot be serialized/deserialized