From f8fe50ad09032728c7475dc668f01fded167b1ee Mon Sep 17 00:00:00 2001 From: Oliver Saggau Date: Sun, 14 Jun 2020 15:14:07 +0200 Subject: [PATCH] HHH-14071 Fix binding for FetchProfile for OneToOne(mappedBy=...) associations --- ...AnnotationMetadataSourceProcessorImpl.java | 5 +++- .../org/hibernate/cfg/AnnotationBinder.java | 23 +++++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/annotations/AnnotationMetadataSourceProcessorImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/annotations/AnnotationMetadataSourceProcessorImpl.java index 9334d922af..f939a1cd7d 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/annotations/AnnotationMetadataSourceProcessorImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/annotations/AnnotationMetadataSourceProcessorImpl.java @@ -252,6 +252,7 @@ public class AnnotationMetadataSourceProcessorImpl implements MetadataSourceProc } AnnotationBinder.bindClass( clazz, inheritanceStatePerClass, rootMetadataBuildingContext ); + AnnotationBinder.bindFetchProfilesForClass( clazz, rootMetadataBuildingContext ); processedEntityNames.add( clazz.getName() ); } } @@ -301,7 +302,9 @@ public class AnnotationMetadataSourceProcessorImpl implements MetadataSourceProc @Override public void postProcessEntityHierarchies() { - + for ( String annotatedPackage : annotatedPackages ) { + AnnotationBinder.bindFetchProfilesForPackage( annotatedPackage, rootMetadataBuildingContext ); + } } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/AnnotationBinder.java b/hibernate-core/src/main/java/org/hibernate/cfg/AnnotationBinder.java index 488c8b1cbc..9ec2044926 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/AnnotationBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/AnnotationBinder.java @@ -349,7 +349,6 @@ public final class AnnotationBinder { bindQueries( pckg, context ); bindFilterDefs( pckg, context ); bindTypeDefs( pckg, context ); - bindFetchProfiles( pckg, context ); BinderHelper.bindAnyMetaDefs( pckg, context ); } @@ -587,7 +586,6 @@ public final class AnnotationBinder { bindQueries( clazzToProcess, context ); bindFilterDefs( clazzToProcess, context ); bindTypeDefs( clazzToProcess, context ); - bindFetchProfiles( clazzToProcess, context ); BinderHelper.bindAnyMetaDefs( clazzToProcess, context ); String schema = ""; @@ -1417,6 +1415,27 @@ public final class AnnotationBinder { } + public static void bindFetchProfilesForClass(XClass clazzToProcess, MetadataBuildingContext context) { + bindFetchProfiles( clazzToProcess, context ); + } + + public static void bindFetchProfilesForPackage(String packageName, MetadataBuildingContext context) { + XPackage pckg; + try { + pckg = context.getBootstrapContext().getReflectionManager().packageForName( packageName ); + } + catch (ClassLoadingException e) { + LOG.packageNotFound( packageName ); + return; + } + catch ( ClassNotFoundException cnf ) { + LOG.packageNotFound( packageName ); + return; + } + + bindFetchProfiles( pckg, context ); + } + private static void bindFetchProfiles(XAnnotatedElement annotatedElement, MetadataBuildingContext context) { FetchProfile fetchProfileAnnotation = annotatedElement.getAnnotation( FetchProfile.class ); FetchProfiles fetchProfileAnnotations = annotatedElement.getAnnotation( FetchProfiles.class );