HHH-6723 : Remove extra join from eager @OneToOne

This commit is contained in:
Gail Badner 2011-10-25 23:00:12 -07:00
parent c42decf774
commit 67662d2759
2 changed files with 17 additions and 9 deletions

View File

@ -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;
}

View File

@ -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();