From f2dbe7a9cbd43c441e41599989cf5c436caef089 Mon Sep 17 00:00:00 2001 From: Gavin Date: Mon, 22 May 2023 14:58:01 +0200 Subject: [PATCH] HHH-16666 allow fetch profiles to be defined using the @Fetch annotation 1. You may now declare an empty named @FetchProfile, and 2. add associations to it using @Fetch. Note that @Fetch becomes a repeatable annotation. --- .../java/org/hibernate/annotations/Fetch.java | 27 ++++-- .../hibernate/annotations/FetchProfile.java | 14 ++- .../org/hibernate/annotations/Fetches.java | 23 +++++ .../boot/model/internal/AnnotationBinder.java | 49 ++++++++--- .../boot/model/internal/CollectionBinder.java | 49 +++++++++-- ...Pass.java => FetchOverrideSecondPass.java} | 35 +++----- .../boot/model/internal/FetchSecondPass.java | 64 ++++++++++++++ .../boot/model/internal/ToOneBinder.java | 52 +++++++++-- .../fetchprofile/NewFetchTest.java | 87 +++++++++++++++++++ 9 files changed, 342 insertions(+), 58 deletions(-) create mode 100644 hibernate-core/src/main/java/org/hibernate/annotations/Fetches.java rename hibernate-core/src/main/java/org/hibernate/boot/model/internal/{VerifyFetchProfileReferenceSecondPass.java => FetchOverrideSecondPass.java} (56%) create mode 100644 hibernate-core/src/main/java/org/hibernate/boot/model/internal/FetchSecondPass.java create mode 100644 hibernate-core/src/test/java/org/hibernate/orm/test/annotations/fetchprofile/NewFetchTest.java diff --git a/hibernate-core/src/main/java/org/hibernate/annotations/Fetch.java b/hibernate-core/src/main/java/org/hibernate/annotations/Fetch.java index 54a7253a48..bb3132314a 100644 --- a/hibernate-core/src/main/java/org/hibernate/annotations/Fetch.java +++ b/hibernate-core/src/main/java/org/hibernate/annotations/Fetch.java @@ -6,13 +6,18 @@ */ package org.hibernate.annotations; -import java.lang.annotation.ElementType; +import java.lang.annotation.Repeatable; import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + /** - * Specifies the default fetching strategy for the annotated association. + * Specifies the default fetching strategy for the annotated association, + * or, if {@link #profile} is specified, the fetching strategy for the + * annotated association in the named {@linkplain FetchProfile fetch profile}. *

* When this annotation is not explicitly specified, then: *