diff --git a/hibernate-core/src/main/java/org/hibernate/loader/AbstractEntityJoinWalker.java b/hibernate-core/src/main/java/org/hibernate/loader/AbstractEntityJoinWalker.java index 432fd0e3bc..f95d0ee91a 100755 --- a/hibernate-core/src/main/java/org/hibernate/loader/AbstractEntityJoinWalker.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/AbstractEntityJoinWalker.java @@ -25,6 +25,7 @@ package org.hibernate.loader; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Iterator; @@ -186,6 +187,21 @@ public abstract class AbstractEntityJoinWalker extends JoinWalker { public abstract String getComment(); + @Override + protected boolean isDuplicateAssociation( + final String foreignKeyTable, + final String[] foreignKeyColumns + ) { + //disable a join back to this same association + final boolean isSameJoin = + persister.getTableName().equals( foreignKeyTable ) && + Arrays.equals( foreignKeyColumns, persister.getKeyColumnNames() ); + return isSameJoin || + super.isDuplicateAssociation(foreignKeyTable, foreignKeyColumns); + } + + + protected final Loadable getPersister() { return persister; } diff --git a/hibernate-testsuite/src/test/java/org/hibernate/test/annotations/onetoone/OneToOneTest.java b/hibernate-testsuite/src/test/java/org/hibernate/test/annotations/onetoone/OneToOneTest.java index d689f7b4b3..80a676b6b1 100644 --- a/hibernate-testsuite/src/test/java/org/hibernate/test/annotations/onetoone/OneToOneTest.java +++ b/hibernate-testsuite/src/test/java/org/hibernate/test/annotations/onetoone/OneToOneTest.java @@ -299,19 +299,11 @@ public class OneToOneTest extends TestCase { } /** - * HHH-5109 @OneToOne - too many joins - * I backed out of the fix for HHH-5109 because it caused HHH-4982. - * It needs to be fixed again by HHH-6723. - * * This test uses an interceptor to verify that correct number of joins * are generated. */ public void testPkOneToOneSelectStatementDoesNotGenerateExtraJoin() { - - //"FailureExpected" doesn't work here, so until it is fixed (again) by HHH-6723, - // we expect an extra join, new JoinCounter(2) is used to get the test to pass. - // Session s = openSession(new JoinCounter(1)); - Session s = openSession(new JoinCounter(2)); + Session s = openSession(new JoinCounter(1)); Transaction tx = s.beginTransaction(); Owner owner = new Owner(); OwnerAddress address = new OwnerAddress();