diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataImpl.java index 4f54ea3c14..6c14b14468 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataImpl.java @@ -400,7 +400,10 @@ public void addFetchProfile(FetchProfile profile) { if ( profile == null || profile.getName() == null ) { throw new IllegalArgumentException( "Fetch profile object or name is null: " + profile ); } - fetchProfiles.put( profile.getName(), profile ); + FetchProfile old = fetchProfiles.put( profile.getName(), profile ); + if ( old != null ) { + LOG.warn( "Duplicated fetch profile with same name [" + profile.getName() + "] found." ); + } } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/HibernateMappingProcessor.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/HibernateMappingProcessor.java index 085a443570..e7549283f2 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/HibernateMappingProcessor.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/HibernateMappingProcessor.java @@ -228,6 +228,49 @@ public void processMappingDependentMetadata() { private void processFetchProfiles() { processFetchProfiles( mappingRoot().getFetchProfile(), null ); + for ( JaxbClassElement classElement : mappingRoot().getClazz() ) { + processFetchProfiles( + classElement.getFetchProfile(), mappingDocument.getMappingLocalBindingContext() + .qualifyClassName( classElement.getName() ) + ); + + // processing fetch profiles defined in the + processFetchProfilesInJoinedSubclass(classElement.getJoinedSubclass()); + // + processFetchProfilesInUnionSubclass( classElement.getUnionSubclass() ); + // + processFetchProfilesInSubclass( classElement.getSubclass() ); + } + } + + private void processFetchProfilesInSubclass(List subclass) { + for ( JaxbSubclassElement subclassElement : subclass ) { + processFetchProfiles( + subclassElement.getFetchProfile(), mappingDocument.getMappingLocalBindingContext() + .qualifyClassName( subclassElement.getName() ) + ); + processFetchProfilesInSubclass( subclassElement.getSubclass() ); + } + } + + private void processFetchProfilesInUnionSubclass(List unionSubclass) { + for ( JaxbUnionSubclassElement subclassElement : unionSubclass ) { + processFetchProfiles( + subclassElement.getFetchProfile(), mappingDocument.getMappingLocalBindingContext() + .qualifyClassName( subclassElement.getName() ) + ); + processFetchProfilesInUnionSubclass( subclassElement.getUnionSubclass() ); + } + } + + private void processFetchProfilesInJoinedSubclass(List joinedSubclassElements) { + for ( JaxbJoinedSubclassElement subclassElement : joinedSubclassElements ) { + processFetchProfiles( + subclassElement.getFetchProfile(), mappingDocument.getMappingLocalBindingContext() + .qualifyClassName( subclassElement.getName() ) + ); + processFetchProfilesInJoinedSubclass( subclassElement.getJoinedSubclass() ); + } } public void processFetchProfiles(List fetchProfiles, String containingEntityName) { diff --git a/hibernate-core/src/test/java/org/hibernate/test/fetchprofiles/join/JoinFetchProfileTest.java b/hibernate-core/src/test/java/org/hibernate/test/fetchprofiles/join/JoinFetchProfileTest.java index c71f1d0dc6..5d0643b1b1 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/fetchprofiles/join/JoinFetchProfileTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/fetchprofiles/join/JoinFetchProfileTest.java @@ -32,7 +32,6 @@ import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Environment; import org.hibernate.engine.spi.SessionImplementor; -import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import static org.junit.Assert.assertEquals; @@ -174,7 +173,6 @@ public void perform(TestData data) { } @Test - @FailureExpectedWithNewMetamodel public void testBasicFetchProfileOperation() { assertTrue( "fetch profile not parsed properly", sessionFactory().containsFetchProfileDefinition( "enrollment.details" ) ); assertTrue( "fetch profile not parsed properly", sessionFactory().containsFetchProfileDefinition( "offering.details" ) ); @@ -237,7 +235,6 @@ public void perform(TestData data) { } @Test - @FailureExpectedWithNewMetamodel public void testLoadOneToManyFetchProfile() { performWithStandardData( new TestCode() { @@ -257,7 +254,6 @@ public void perform(TestData data) { } @Test - @FailureExpectedWithNewMetamodel public void testLoadDeepFetchProfile() { performWithStandardData( new TestCode() { @@ -281,7 +277,6 @@ public void perform(TestData data) { } @Test - @FailureExpectedWithNewMetamodel public void testLoadComponentDerefFetchProfile() { performWithStandardData( new TestCode() { @@ -306,7 +301,6 @@ public void perform(TestData data) { * TODO : this is actually not strictly true. what we should have happen is to subsequently load those fetches */ @Test - @FailureExpectedWithNewMetamodel public void testHQL() { performWithStandardData( new TestCode() {