diff --git a/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultLoadEventListener.java b/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultLoadEventListener.java index 7b33d86f83..4ffe2512d8 100644 --- a/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultLoadEventListener.java +++ b/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultLoadEventListener.java @@ -288,12 +288,7 @@ public class DefaultLoadEventListener implements LoadEventListener { 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 ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/proxy/LazyToOnesProxyWithSubclassesTest.java b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/proxy/LazyToOnesProxyWithSubclassesTest.java index e14705ae9c..f19dd3d1cc 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/proxy/LazyToOnesProxyWithSubclassesTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/proxy/LazyToOnesProxyWithSubclassesTest.java @@ -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; + } } } \ No newline at end of file