Skip to content

Commit 66c48fa

Browse files
committed
HHH-4309 Add documentation explaining how overriding generators work
1 parent 60c6535 commit 66c48fa

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

documentation/src/main/asciidoc/userguide/chapters/domain/identifiers.adoc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
:core-project-dir: {root-project-dir}/hibernate-core
55
:core-test-base: {core-project-dir}/src/test/java/org/hibernate/orm/test
66
:example-dir-identifier: {core-test-base}/mapping/identifier
7+
:example-dir-generated: {core-test-base}/mapping/generated
78
:example-dir-associations: {core-test-base}/associations
89
:jpaJavadocUrl: https://javadoc.io/doc/jakarta.persistence/jakarta.persistence-api/latest/jakarta.persistence
910
:extrasdir: extras
@@ -392,6 +393,24 @@ include::{example-dir-identifier}/SequenceGeneratorConfiguredTest.java[tag=ident
392393
Again the mapping specifies `explicit_product_sequence` as the physical sequence name, but it also specifies an
393394
explicit allocation-size ("increment by").
394395

396+
The scope of the generator name can be controlled with the <<settings-hibernate.jpa.compliance.global_id_generators,`hibernate.jpa.compliance.global_id_generators`>>
397+
configuration setting. With <<settings-compliance,JPA compliance>> enabled, the name scope is global i.e.
398+
there may not be two generator definitions with the same name. Historically, Hibernate ORM used a local scope i.e.
399+
every managed type may have a generator with the same name, preferring the "local" definition over a more distant one.
400+
This behavior allows to model e.g. a mapped superclass with a generator that should apply to subclasses by default,
401+
yet allow an entity subclass to choose a custom generator by simply specifying the same generator name.
402+
403+
[[identifiers-generators-sequence-override]]
404+
.Sequence override
405+
====
406+
[source,java]
407+
----
408+
include::{example-dir-generated}/override/SequenceGeneratorOverrideTest.java[tag=identifiers-generators-sequence-override-example, indent=0]
409+
----
410+
====
411+
412+
In this case, `base_sequence` will be used when a `Entity1` is persisted,
413+
whereas for persists of a `Entity2`, Hibernate ORM will use `sub_sequence`.
395414

396415
[[identifiers-generators-identity]]
397416
==== Using IDENTITY columns

0 commit comments

Comments
 (0)