From fe5a7466cfb661608117c4e7c93ff3e6068b8ac3 Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Sat, 18 Dec 2021 07:21:35 -0600 Subject: [PATCH] slightly expand the documentation for Boolean - minor fix-ups --- .../chapters/domain/basic_types.adoc | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/documentation/src/main/asciidoc/userguide/chapters/domain/basic_types.adoc b/documentation/src/main/asciidoc/userguide/chapters/domain/basic_types.adoc index 2cf1d5272e..d4a4e34bbd 100644 --- a/documentation/src/main/asciidoc/userguide/chapters/domain/basic_types.adoc +++ b/documentation/src/main/asciidoc/userguide/chapters/domain/basic_types.adoc @@ -412,20 +412,14 @@ include::{sourcedir}/basic/BooleanMappingTests.java[tags=basic-boolean-example-i ---- ==== -But, especially when working with a legacy database, it's quite common to find boolean values -encoded as a character, or as an integer, even when the platform _does_ support a built-in -`BOOLEAN` type. - -The easiest way to handle this situation is to use a JPA `AttributeConverter`. You can easily -write your own `AttributeConverter`, but for your convenience, Hibernate comes with three -built-in converters for common cases: +However, it is quite common to find boolean values encoded as a character or as an integer. +Such cases are exactly the intention of `AttributeConverter`. For convenience, Hibernate +provides 3 built-in converters for the common boolean mapping cases: - `YesNoConverter` encodes a boolean value as `'Y'` or `'N'`, - `TrueFalseConverter` encodes a boolean value as `'T'` or `'F'`, and - `NumericBooleanConverter` encodes the value as an integer, `1` for true, and `0` for false. -You may specify the converter to use with the `@Convert` annotation. - [[basic-boolean-example-converted]] .Using `AttributeConverter` ==== @@ -439,8 +433,10 @@ include::{sourcedir}/basic/BooleanMappingTests.java[tags=basic-boolean-example-e ---- ==== -Of course, if you need to do something really special, a boolean value can also be mapped using -`@CustomType` and your own `UserType`. +If the boolean value is defined in the database as something other than `BOOLEAN`, character or integer, +the value can also be mapped using a custom `AttributeConverter` - see <>. + +A `UserType` may also be used - see <> // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -1546,6 +1542,8 @@ There are also corresponding, specialized forms of `@CustomType` for specific mo * For other collection mappings, `@CustomType` describes the elements * For discriminated association mappings (`@Any` and `@ManyToAny`), `@CustomType` describes the discriminator value +`@UserType` allows for more complex mapping concerns; but, < and +<> should generally be preferred as simpler solutions [[basic-nationalized]] ==== Handling nationalized character data