From e8c2824976a4dbfb3a1f0f7977be57b50a495603 Mon Sep 17 00:00:00 2001 From: Gavin Date: Sat, 17 Dec 2022 17:57:05 +0100 Subject: [PATCH] allow use of SelectGenerator from annotations - generalize @GenericGenerator to any Generator - add tests for @GenericGenerator(type=SelectGenerator) - move some logic for choosing the right InsertGeneratedIdentifierDelegate to the generators themselves --- .../annotations/GenericGenerator.java | 17 +++-- .../org/hibernate/cfg/AnnotationBinder.java | 4 +- .../generator/InDatabaseGenerator.java | 15 ++-- .../org/hibernate/id/IdentityGenerator.java | 29 ++++++++ .../id/PostInsertIdentifierGenerator.java | 2 +- .../org/hibernate/id/SelectGenerator.java | 45 ++++++++++-- .../InsertGeneratedIdentifierDelegate.java | 7 +- .../entity/AbstractEntityPersister.java | 28 +------- .../persister/entity/EntityPersister.java | 8 --- .../temptable/InsertExecutionDelegate.java | 7 +- .../selectannotated/MyEntity.hbm.xml | 31 ++++++++ .../selectannotated/MyEntity.java | 48 +++++++++++++ .../selectannotated/SelectGeneratorTest.java | 71 +++++++++++++++++++ 13 files changed, 243 insertions(+), 69 deletions(-) create mode 100644 hibernate-core/src/test/java/org/hibernate/orm/test/generatedkeys/selectannotated/MyEntity.hbm.xml create mode 100644 hibernate-core/src/test/java/org/hibernate/orm/test/generatedkeys/selectannotated/MyEntity.java create mode 100644 hibernate-core/src/test/java/org/hibernate/orm/test/generatedkeys/selectannotated/SelectGeneratorTest.java diff --git a/hibernate-core/src/main/java/org/hibernate/annotations/GenericGenerator.java b/hibernate-core/src/main/java/org/hibernate/annotations/GenericGenerator.java index 12ed1c575d..e1a172d803 100644 --- a/hibernate-core/src/main/java/org/hibernate/annotations/GenericGenerator.java +++ b/hibernate-core/src/main/java/org/hibernate/annotations/GenericGenerator.java @@ -6,7 +6,7 @@ */ package org.hibernate.annotations; -import org.hibernate.generator.InMemoryGenerator; +import org.hibernate.generator.Generator; import java.lang.annotation.Repeatable; import java.lang.annotation.Retention; @@ -19,11 +19,10 @@ import static java.lang.annotation.ElementType.TYPE; import static java.lang.annotation.RetentionPolicy.RUNTIME; /** - * Defines a named identifier generator, an instance of the interface - * {@link org.hibernate.id.IdentifierGenerator}. This allows the use of - * custom identifier generation strategies beyond those provided by the - * four basic JPA-defined {@linkplain jakarta.persistence.GenerationType - * generation types}. + * Defines a named identifier generator, usually an instance of the interface + * {@link org.hibernate.id.IdentifierGenerator}. This allows the use of custom + * identifier generation strategies beyond those provided by the four basic + * JPA-defined {@linkplain jakarta.persistence.GenerationType generation types}. *

* A named generator may be associated with an entity class by: *