diff --git a/hibernate-core/src/main/java/org/hibernate/loader/plan/spi/build/AbstractLoadPlanBuilderStrategy.java b/hibernate-core/src/main/java/org/hibernate/loader/plan/spi/build/AbstractLoadPlanBuilderStrategy.java index cbf293149e..ac8ba7261e 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/plan/spi/build/AbstractLoadPlanBuilderStrategy.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/plan/spi/build/AbstractLoadPlanBuilderStrategy.java @@ -416,6 +416,11 @@ public abstract class AbstractLoadPlanBuilderStrategy implements LoadPlanBuilder private Map fetchedAssociationKeyOwnerMap = new HashMap(); + @Override + public boolean isDuplicateAssociationKey(AssociationKey associationKey) { + return fetchedAssociationKeyOwnerMap.containsKey( associationKey ); + } + @Override public void associationKeyRegistered(AssociationKey associationKey) { // todo : use this information to maintain a map of AssociationKey->FetchOwner mappings (associationKey + current fetchOwner stack entry) diff --git a/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/spi/AbstractLoadPlanBuildingAssociationVisitationStrategy.java b/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/spi/AbstractLoadPlanBuildingAssociationVisitationStrategy.java index 286d3060f5..60ecc12117 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/spi/AbstractLoadPlanBuildingAssociationVisitationStrategy.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/spi/AbstractLoadPlanBuildingAssociationVisitationStrategy.java @@ -553,6 +553,11 @@ public abstract class AbstractLoadPlanBuildingAssociationVisitationStrategy private Map fetchedAssociationKeySourceMap = new HashMap(); + @Override + public boolean isDuplicateAssociationKey(AssociationKey associationKey) { + return fetchedAssociationKeySourceMap.containsKey( associationKey ); + } + @Override public void associationKeyRegistered(AssociationKey associationKey) { // todo : use this information to maintain a map of AssociationKey->FetchSource mappings (associationKey + current FetchSource stack entry) diff --git a/hibernate-core/src/main/java/org/hibernate/persister/walking/spi/AssociationVisitationStrategy.java b/hibernate-core/src/main/java/org/hibernate/persister/walking/spi/AssociationVisitationStrategy.java index 22d0649431..519cbe468e 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/walking/spi/AssociationVisitationStrategy.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/walking/spi/AssociationVisitationStrategy.java @@ -170,4 +170,6 @@ public interface AssociationVisitationStrategy { public void associationKeyRegistered(AssociationKey associationKey); public FetchSource registeredFetchSource(AssociationKey associationKey); public void foundCircularAssociation(AssociationAttributeDefinition attributeDefinition); + public boolean isDuplicateAssociationKey(AssociationKey associationKey); + } diff --git a/hibernate-core/src/main/java/org/hibernate/persister/walking/spi/MetamodelGraphWalker.java b/hibernate-core/src/main/java/org/hibernate/persister/walking/spi/MetamodelGraphWalker.java index 8712569a13..0c87a392a3 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/walking/spi/MetamodelGraphWalker.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/walking/spi/MetamodelGraphWalker.java @@ -291,6 +291,6 @@ public class MetamodelGraphWalker { * false, otherwise. */ protected boolean isDuplicateAssociationKey(AssociationKey associationKey) { - return visitedAssociationKeys.contains( associationKey ); + return visitedAssociationKeys.contains( associationKey ) || strategy.isDuplicateAssociationKey( associationKey ); } } diff --git a/hibernate-core/src/test/java/org/hibernate/test/loadplans/walking/LoggingAssociationVisitationStrategy.java b/hibernate-core/src/test/java/org/hibernate/test/loadplans/walking/LoggingAssociationVisitationStrategy.java index d7a2f99ef4..c31bc8e323 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/loadplans/walking/LoggingAssociationVisitationStrategy.java +++ b/hibernate-core/src/test/java/org/hibernate/test/loadplans/walking/LoggingAssociationVisitationStrategy.java @@ -263,4 +263,9 @@ public class LoggingAssociationVisitationStrategy implements AssociationVisitati ); } + @Override + public boolean isDuplicateAssociationKey(AssociationKey associationKey) { + return false; //To change body of implemented methods use File | Settings | File Templates. + } + }