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 aType, 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
Forbasic types, we prefer to model the type mapping in terms the combination of: AJdbcType is able to read and write a single Java type to one, or sometimes several,JDBC types.
AJavaType 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 partnerJdbcType.
For example, if an entity attribute of Java typeBigInteger is mapped to the JDBC typeTypes.VARCHAR, theVarcharJdbcType will ask itsBigIntegerJavaType to convert instances ofBigInteger to and fromString when writing to and reading from JDBC statements and result sets.
An important point is that the set of availableJavaTypes and of availableJdbcTypes is not fixed—aTypeConfiguration iscustomizable 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, aconverter may assist in the conversion process. For example, a JPAAttributeConverter might be provided.
AJavaType comes with a built-inMutabilityPlan, but this may be overridden when types are composed.
Seeorg.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 theType 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 Javaboolean tochar(1) orinteger 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-definedConverter annotation.
- Related PackagesPackageDescriptionThis package defines the central Hibernate APIs, beginning with
SessionFactory, which represents an instance of Hibernate at runtime and is the source of new instances ofSessionandStatelessSession, the most important APIs exposing persistence-related operations for entities.Contracts for reading and writing values to and from JDBC.Support for type mappings which format composite values to a structured text format (JSON or XML) for storage in a database-specific column type supporting that structured format.Defines a registry for HibernateTypes. - 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 namedquery 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).Handlesembedded mappings.Represents acomposite 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 impliedconversion.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 themetadata 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 extendsSerializable>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 suppliedconverter 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 JDBCtypes, 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'