From e846fd88d9aa10455276c88f02a84ce0e8ab6c4f Mon Sep 17 00:00:00 2001 From: Gavin Date: Thu, 18 May 2023 12:09:08 +0200 Subject: [PATCH] add discrete headings to section on compositional basic types --- .../src/main/asciidoc/introduction/Entities.adoc | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/documentation/src/main/asciidoc/introduction/Entities.adoc b/documentation/src/main/asciidoc/introduction/Entities.adoc index e7e56516b0..7e662b2fd2 100644 --- a/documentation/src/main/asciidoc/introduction/Entities.adoc +++ b/documentation/src/main/asciidoc/introduction/Entities.adoc @@ -726,6 +726,7 @@ BitSet bitset; All this is nice, but it probably won't surprise you that Hibernate goes beyond what is required by JPA. +[[compositional-basic-types]] === Compositional basic types Hibernate considers a "basic type" to be formed by the marriage of two objects: @@ -733,8 +734,13 @@ Hibernate considers a "basic type" to be formed by the marriage of two objects: - a `JavaType`, which models the semantics of a certain Java class, and - a `JdbcType`, representing a SQL type which is understood by JDBC. +When mapping a basic attribute, we may explicitly specify a `JavaType`, a `JdbcType`, or both. + +[discrete] +==== JavaType + An instance of `org.hibernate.type.descriptor.java.JavaType` represents a particular Java class. -It is able to: +It's able to: - compare instances of the class to determine if an attribute of that class type is dirty (modified), - produce a useful hash code for an instance of the class, @@ -761,6 +767,9 @@ BitSet bitSet; Alternatively, the `@JavaTypeRegistration` annotation may be used to register `BitSetJavaType` as the default `JavaType` for `BitSet`. +[discrete] +==== JdbcType + A `org.hibernate.type.descriptor.jdbc.JdbcType` is able to read and write a single Java type from and to JDBC. For example, `VarcharJdbcType` takes care of: @@ -798,6 +807,9 @@ Since Hibernate understand more SQL types than JDBC, there's an extended list of For example, `SqlTypes.GEOMETRY` represents the spatial data type `GEOMETRY`. **** +[discrete] +==== AttributeConverter + If a given `JavaType` doesn't know how to convert its instances to the type required by its partner `JdbcType`, we must help it out by providing a JPA `AttributeConverter` to perform the conversion. For example, to form a basic type using `LongJavaType` and `TimestampJdbcType`, we would provide an `AttributeConverter`.