From 2bbb3074d4d484e12cad3c0117c5453ce3793e1e Mon Sep 17 00:00:00 2001 From: Gail Badner Date: Wed, 12 Oct 2011 04:26:57 -0700 Subject: [PATCH] HHH-6723 : Remove extra join from eager @OneToOne --- .../loader/AbstractEntityJoinWalker.java | 16 ++++++++++++++++ .../test/annotations/onetoone/OneToOneTest.java | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) 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 5f8360a9da..1dfa9966b3 100755 --- a/hibernate-core/src/main/java/org/hibernate/loader/AbstractEntityJoinWalker.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/AbstractEntityJoinWalker.java @@ -24,6 +24,7 @@ */ package org.hibernate.loader; import java.util.ArrayList; +import java.util.Arrays; import java.util.Iterator; import java.util.List; @@ -185,6 +186,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-core/src/matrix/java/org/hibernate/test/annotations/onetoone/OneToOneTest.java b/hibernate-core/src/matrix/java/org/hibernate/test/annotations/onetoone/OneToOneTest.java index 946cd8ab13..3559081e2e 100644 --- a/hibernate-core/src/matrix/java/org/hibernate/test/annotations/onetoone/OneToOneTest.java +++ b/hibernate-core/src/matrix/java/org/hibernate/test/annotations/onetoone/OneToOneTest.java @@ -331,7 +331,7 @@ public class OneToOneTest extends BaseCoreFunctionalTestCase { } @Test - @FailureExpected( jiraKey = "HHH-6723" ) + @TestForIssue( jiraKey = "HHH-6723" ) public void testPkOneToOneSelectStatementDoesNotGenerateExtraJoin() { // This test uses an interceptor to verify that correct number of joins are generated. Session s = openSession(new JoinCounter(1));