HHH-13640 - Fix initialization of existing proxy association leaf subclass

(cherry picked from commit cec4228d70)
This commit is contained in:
Andrea Boriero 2019-10-02 16:51:37 +01:00 committed by gbadner
parent 8b855d631b
commit a3ec300866
2 changed files with 25 additions and 8 deletions

View File

@ -306,12 +306,7 @@ public class DefaultLoadEventListener extends AbstractLockUpgradeEventListener i
LazyInitializer li = ( (HibernateProxy) proxy ).getHibernateLazyInitializer();
if ( li.isUnwrap() ) {
if ( entityMetamodel.hasSubclasses() ) {
LOG.debug( "Ignoring NO_PROXY for to-one association with subclasses to honor laziness" );
}
else {
return li.getImplementation();
}
LOG.debug( "Ignoring NO_PROXY to honor laziness" );
}
return persistenceContext.narrowProxy( proxy, persister, keyToLoad, null );

View File

@ -24,7 +24,6 @@ import org.hibernate.cfg.AvailableSettings;
import org.hibernate.proxy.HibernateProxy;
import org.hibernate.stat.Statistics;
import org.hibernate.testing.FailureExpected;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
@ -155,7 +154,6 @@ public class LazyToOnesProxyWithSubclassesTest extends BaseNonConfigCoreFunction
}
@Test
@FailureExpected( jiraKey = "HHH-13640" )
public void testExistingProxyAssociationLeafSubclass() {
inTransaction(
session -> {
@ -187,6 +185,12 @@ public class LazyToOnesProxyWithSubclassesTest extends BaseNonConfigCoreFunction
// an uninitialized non-HibernateProxy proxy?
assertEquals( 1, stats.getPrepareStatementCount() );
Human human = otherEntity.getHuman();
human.getName();
assertEquals( 1, stats.getPrepareStatementCount() );
human.getSex();
assertEquals( 2, stats.getPrepareStatementCount() );
}
);
}
@ -239,6 +243,8 @@ public class LazyToOnesProxyWithSubclassesTest extends BaseNonConfigCoreFunction
@Table(name = "Human")
public static class Human extends Primate {
private String sex;
public Human(String name) {
this();
setName( name );
@ -247,6 +253,14 @@ public class LazyToOnesProxyWithSubclassesTest extends BaseNonConfigCoreFunction
protected Human() {
// this form used by Hibernate
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
}
@Entity(name = "OtherEntity")
@ -279,5 +293,13 @@ public class LazyToOnesProxyWithSubclassesTest extends BaseNonConfigCoreFunction
public String getId() {
return id;
}
public Human getHuman() {
return human;
}
public void setHuman(Human human) {
this.human = human;
}
}
}