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 JavaTypes and of available
JdbcTypes 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
UserTypemay 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
CompositeUserTypedefines a way to handle multi-column type mappings, and is a much more flexible form ofEmbeddableobject mapping.
Built-in converters for boolean mappings
In older versions of Hibernate there were dedicatedTypes 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 as1or0.
These converters may be applied, as usual, using the JPA-defined
Converter annotation.
- See Also:
-
ClassDescriptionTODO : javadocConvenience base class for
BasicTypeimplementations.Abstract superclass of the built-inTypehierarchy.Extension contract forBasicTypeimplementations 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 betweenARRAYandT[]A type that maps betweenARRAYandCollection<T>BasicPluralType<C,E> A basic plural type.BasicType<T>Marker interface for basic types.A basic type reference.A registry ofBasicTypeinstancesBindableType<J>Represents a type of argument which can be bound to a positional or named query parameter.A context within which aBindableTypecan be resolved to an instance ofSqmExpressible.A type that is assignable to every non-primitive type, that is, the type ofnull.A type that handles HibernatePersistentCollections (including arrays).Handles embedded mappings.Represents a composite type, a type which itself has typed attributes.ConvertedBasicArrayType<T,S, E> Given aBasicValueConverterfor an array type,A converted basic array type.Extension for implementations ofBasicTypewhich have an implied conversion.A custom type for mapping user-written classes that implementPersistentCollectionCustomType<J>Base for types which map associations to persistent entities.Represents directionality of the foreign key constraintA many-to-one association to an entity.Declares operations used by implementors ofTypethat are common to the fully-"compiled" runtime mapping metadata held by aSessionFactoryand the incomplete metamodel which exists during the metadata building process.Handles conversion to/fromBooleanas0(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.Specialization ofDomainTypefor types that can be used as a parameter output for aProcedureCall.OptionalTypecontract for implementations that are aware of how to extract values from stored procedure OUT/INOUT parameters.OptionalTypecontract for implementations enabled to set store procedure OUT/INOUT parameters values by name.SerializableType<T extends Serializable>A type that maps between aVARBINARYandSerializableclasses.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 common instances ofBasicTypeReference.A 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.Enumerates the possible storage strategies for offset or zoned datetimes.Handles conversion to/fromBooleanas'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.HandlesCompositeUserTypes.Possible options for how to handleByte[]andCharacter[]basic mappings encountered in the application domain model.Handles conversion to/fromBooleanas'Y'or'N'