From d88bf908dac95720051b627573b6541362973bb2 Mon Sep 17 00:00:00 2001 From: Vlad Mihalcea Date: Mon, 29 Aug 2016 17:29:41 +0300 Subject: [PATCH] HHH-11069 - Improve documentation regarding GenerationType.AUTO Explain the two IdGeneratorStrategyInterpreter implementations and their relation to how AUTO resolves to an actual identifier strategy --- .../chapters/domain/identifiers.adoc | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/documentation/src/main/asciidoc/userguide/chapters/domain/identifiers.adoc b/documentation/src/main/asciidoc/userguide/chapters/domain/identifiers.adoc index c54f91e072..21161c6ac0 100644 --- a/documentation/src/main/asciidoc/userguide/chapters/domain/identifiers.adoc +++ b/documentation/src/main/asciidoc/userguide/chapters/domain/identifiers.adoc @@ -221,17 +221,21 @@ The rest of the discussion here assumes this setting is enabled (true). ==== Interpreting AUTO How a persistence provider interprets the AUTO generation type is left up to the provider. -Hibernate interprets it in the following order: -* If the given name matches the name for a `javax.persistence.SequenceGenerator` annotation then <>. -* If the given name matches the name for a `javax.persistence.TableGenerator` annotation then <>. -* If the given name matches the name for a `org.hibernate.annotations.GenericGenerator` annotation then <>. +The default behavior is to look at the java type of the identifier attribute. -The fallback is to consult with the pluggable `org.hibernate.boot.model.IdGeneratorStrategyInterpreter` contract, which is covered in detail in the Hibernate Integrations Guide. -The default behavior is to look at the java type of the identifier attribute: +If the identifier type is UUID, Hibernate is going to use an <>. -* for UUID <> -* Otherwise, <> +If the identifier type is numerical (e.g. `Long`, `Integer`), then Hibernate is going to use the `IdGeneratorStrategyInterpreter` to resolve the identifier generator strategy. +The `IdGeneratorStrategyInterpreter` has two implementations: + +`FallbackInterpreter`:: + This is the default strategy since Hibernate 5.0. For older versions, this strategy is enabled through the <> configuration property . + When using this strategy, `AUTO` always resolves to `SequenceStyleGenerator`. + If the underlying database supports sequences, then a SEQUENCE generator is used. Otherwise, a TABLE generator is going to be used instead. +`LegacyFallbackInterpreter`:: + This is a legacy mechanism that was used by Hibernate prior to version 5.0 or when the <> configuration property is false. + The legacy strategy maps `AUTO` to the `native` generator strategy which uses the https://docs.jboss.org/hibernate/orm/{majorMinorVersion}/javadocs/org/hibernate/dialect/Dialect.html#getNativeIdentifierGeneratorStrategy--[Dialect#getNativeIdentifierGeneratorStrategy] to resolve the actual identifier generator (e.g. `identity` or `sequence`). [[identifiers-generators-sequence]] ==== Using sequences