Package org.hibernate.type


packageorg.hibernate.type
A HibernateType 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.
  • AUserType 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, aCompositeUserType 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 dedicatedTypes mapping Javaboolean tochar(1) orinteger database columns. These have now been replaced by the converters:

These converters may be applied, as usual, using the JPA-definedConverter annotation.

See Also: