HHH-13640 - Uninitialized HibernateProxy mapped as NO_PROXY gets initialized when reloaded with enhancement-as-proxy enabled
(cherry picked from commit ee304305e8
)
This commit is contained in:
parent
fdb5ba7d4e
commit
ce24b3c389
|
@ -273,6 +273,7 @@ public class DefaultLoadEventListener extends AbstractLockUpgradeEventListener i
|
|||
.getSessionFactoryOptions()
|
||||
.isEnhancementAsProxyEnabled();
|
||||
|
||||
final EntityMetamodel entityMetamodel = persister.getEntityMetamodel();
|
||||
final boolean entityHasHibernateProxyFactory = persister.getEntityMetamodel()
|
||||
.getTuplizer()
|
||||
.getProxyFactory() != null;
|
||||
|
@ -304,21 +305,21 @@ public class DefaultLoadEventListener extends AbstractLockUpgradeEventListener i
|
|||
|
||||
LazyInitializer li = ( (HibernateProxy) proxy ).getHibernateLazyInitializer();
|
||||
|
||||
if ( li.isUnwrap() || event.getShouldUnwrapProxy() ) {
|
||||
return li.getImplementation();
|
||||
if ( li.isUnwrap() ) {
|
||||
if ( entityMetamodel.hasSubclasses() ) {
|
||||
LOG.debug( "Ignoring NO_PROXY for to-one association with subclasses to honor laziness" );
|
||||
}
|
||||
else {
|
||||
return li.getImplementation();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return persistenceContext.narrowProxy( proxy, persister, keyToLoad, null );
|
||||
}
|
||||
|
||||
// specialized handling for entities with subclasses with a HibernateProxy factory
|
||||
if ( persister.getEntityMetamodel().hasSubclasses() ) {
|
||||
// entities with subclasses that define a ProxyFactory can create
|
||||
// a HibernateProxy so long as NO_PROXY was not specified.
|
||||
if ( event.getShouldUnwrapProxy() != null && event.getShouldUnwrapProxy() ) {
|
||||
LOG.debugf( "Ignoring NO_PROXY for to-one association with subclasses to honor laziness" );
|
||||
}
|
||||
if ( entityMetamodel.hasSubclasses() ) {
|
||||
// entities with subclasses that define a ProxyFactory can create a HibernateProxy
|
||||
return createProxy( event, persister, keyToLoad, persistenceContext );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,8 +47,6 @@ public class LoadEvent extends AbstractEvent {
|
|||
private Object result;
|
||||
private PostLoadEvent postLoadEvent;
|
||||
|
||||
private Boolean shouldUnwrapProxy;
|
||||
|
||||
public LoadEvent(Serializable entityId, Object instanceToLoad, EventSource source) {
|
||||
this( entityId, null, instanceToLoad, DEFAULT_LOCK_OPTIONS, false, source );
|
||||
}
|
||||
|
@ -192,19 +190,4 @@ public class LoadEvent extends AbstractEvent {
|
|||
public void setPostLoadEvent(PostLoadEvent postLoadEvent) {
|
||||
this.postLoadEvent = postLoadEvent;
|
||||
}
|
||||
|
||||
public Boolean getShouldUnwrapProxy() {
|
||||
if ( shouldUnwrapProxy == null ) {
|
||||
final boolean enabled = getSession().getFactory()
|
||||
.getSessionFactoryOptions()
|
||||
.isEnhancementAsProxyEnabled();
|
||||
return enabled;
|
||||
}
|
||||
|
||||
return shouldUnwrapProxy;
|
||||
}
|
||||
|
||||
public void setShouldUnwrapProxy(Boolean shouldUnwrapProxy) {
|
||||
this.shouldUnwrapProxy = shouldUnwrapProxy;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1156,11 +1156,11 @@ public final class SessionImpl
|
|||
LoadEvent event = loadEvent;
|
||||
loadEvent = null;
|
||||
event = recycleEventInstance( event, id, entityName );
|
||||
event.setShouldUnwrapProxy( unwrapProxy );
|
||||
fireLoadNoChecks( event, type );
|
||||
Object result = event.getResult();
|
||||
if ( !nullable ) {
|
||||
UnresolvableObjectException.throwIfNull( result, id, entityName );}
|
||||
UnresolvableObjectException.throwIfNull( result, id, entityName );
|
||||
}
|
||||
|
||||
if ( loadEvent == null ) {
|
||||
event.setEntityClassName( null );
|
||||
|
@ -1186,7 +1186,6 @@ public final class SessionImpl
|
|||
event.setLockMode( LoadEvent.DEFAULT_LOCK_MODE );
|
||||
event.setLockScope( LoadEvent.DEFAULT_LOCK_OPTIONS.getScope() );
|
||||
event.setLockTimeout( LoadEvent.DEFAULT_LOCK_OPTIONS.getTimeOut() );
|
||||
event.setShouldUnwrapProxy( null );
|
||||
return event;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,6 @@ import org.hibernate.boot.SessionFactoryBuilder;
|
|||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
|
||||
import org.hibernate.testing.FailureExpected;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
|
||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
|
@ -63,7 +62,6 @@ public class LazyToOnesProxyWithSubclassesTest extends BaseNonConfigCoreFunction
|
|||
}
|
||||
|
||||
@Test
|
||||
@FailureExpected( jiraKey = "HHH-13640")
|
||||
public void testNewProxyAssociation() {
|
||||
inTransaction(
|
||||
session -> {
|
||||
|
@ -87,7 +85,6 @@ public class LazyToOnesProxyWithSubclassesTest extends BaseNonConfigCoreFunction
|
|||
}
|
||||
|
||||
@Test
|
||||
@FailureExpected( jiraKey = "HHH-13640")
|
||||
public void testReusedProxyAssociation() {
|
||||
inTransaction(
|
||||
session -> {
|
||||
|
|
Loading…
Reference in New Issue