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()
|
.getSessionFactoryOptions()
|
||||||
.isEnhancementAsProxyEnabled();
|
.isEnhancementAsProxyEnabled();
|
||||||
|
|
||||||
|
final EntityMetamodel entityMetamodel = persister.getEntityMetamodel();
|
||||||
final boolean entityHasHibernateProxyFactory = persister.getEntityMetamodel()
|
final boolean entityHasHibernateProxyFactory = persister.getEntityMetamodel()
|
||||||
.getTuplizer()
|
.getTuplizer()
|
||||||
.getProxyFactory() != null;
|
.getProxyFactory() != null;
|
||||||
|
@ -304,21 +305,21 @@ public class DefaultLoadEventListener extends AbstractLockUpgradeEventListener i
|
||||||
|
|
||||||
LazyInitializer li = ( (HibernateProxy) proxy ).getHibernateLazyInitializer();
|
LazyInitializer li = ( (HibernateProxy) proxy ).getHibernateLazyInitializer();
|
||||||
|
|
||||||
if ( li.isUnwrap() || event.getShouldUnwrapProxy() ) {
|
if ( li.isUnwrap() ) {
|
||||||
return li.getImplementation();
|
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 );
|
return persistenceContext.narrowProxy( proxy, persister, keyToLoad, null );
|
||||||
}
|
}
|
||||||
|
|
||||||
// specialized handling for entities with subclasses with a HibernateProxy factory
|
// specialized handling for entities with subclasses with a HibernateProxy factory
|
||||||
if ( persister.getEntityMetamodel().hasSubclasses() ) {
|
if ( entityMetamodel.hasSubclasses() ) {
|
||||||
// entities with subclasses that define a ProxyFactory can create
|
// entities with subclasses that define a ProxyFactory can create a HibernateProxy
|
||||||
// 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" );
|
|
||||||
}
|
|
||||||
return createProxy( event, persister, keyToLoad, persistenceContext );
|
return createProxy( event, persister, keyToLoad, persistenceContext );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,8 +47,6 @@ public class LoadEvent extends AbstractEvent {
|
||||||
private Object result;
|
private Object result;
|
||||||
private PostLoadEvent postLoadEvent;
|
private PostLoadEvent postLoadEvent;
|
||||||
|
|
||||||
private Boolean shouldUnwrapProxy;
|
|
||||||
|
|
||||||
public LoadEvent(Serializable entityId, Object instanceToLoad, EventSource source) {
|
public LoadEvent(Serializable entityId, Object instanceToLoad, EventSource source) {
|
||||||
this( entityId, null, instanceToLoad, DEFAULT_LOCK_OPTIONS, false, source );
|
this( entityId, null, instanceToLoad, DEFAULT_LOCK_OPTIONS, false, source );
|
||||||
}
|
}
|
||||||
|
@ -192,19 +190,4 @@ public class LoadEvent extends AbstractEvent {
|
||||||
public void setPostLoadEvent(PostLoadEvent postLoadEvent) {
|
public void setPostLoadEvent(PostLoadEvent postLoadEvent) {
|
||||||
this.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 event = loadEvent;
|
||||||
loadEvent = null;
|
loadEvent = null;
|
||||||
event = recycleEventInstance( event, id, entityName );
|
event = recycleEventInstance( event, id, entityName );
|
||||||
event.setShouldUnwrapProxy( unwrapProxy );
|
|
||||||
fireLoadNoChecks( event, type );
|
fireLoadNoChecks( event, type );
|
||||||
Object result = event.getResult();
|
Object result = event.getResult();
|
||||||
if ( !nullable ) {
|
if ( !nullable ) {
|
||||||
UnresolvableObjectException.throwIfNull( result, id, entityName );}
|
UnresolvableObjectException.throwIfNull( result, id, entityName );
|
||||||
|
}
|
||||||
|
|
||||||
if ( loadEvent == null ) {
|
if ( loadEvent == null ) {
|
||||||
event.setEntityClassName( null );
|
event.setEntityClassName( null );
|
||||||
|
@ -1186,7 +1186,6 @@ public final class SessionImpl
|
||||||
event.setLockMode( LoadEvent.DEFAULT_LOCK_MODE );
|
event.setLockMode( LoadEvent.DEFAULT_LOCK_MODE );
|
||||||
event.setLockScope( LoadEvent.DEFAULT_LOCK_OPTIONS.getScope() );
|
event.setLockScope( LoadEvent.DEFAULT_LOCK_OPTIONS.getScope() );
|
||||||
event.setLockTimeout( LoadEvent.DEFAULT_LOCK_OPTIONS.getTimeOut() );
|
event.setLockTimeout( LoadEvent.DEFAULT_LOCK_OPTIONS.getTimeOut() );
|
||||||
event.setShouldUnwrapProxy( null );
|
|
||||||
return event;
|
return event;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,6 @@ import org.hibernate.boot.SessionFactoryBuilder;
|
||||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||||
import org.hibernate.cfg.AvailableSettings;
|
import org.hibernate.cfg.AvailableSettings;
|
||||||
|
|
||||||
import org.hibernate.testing.FailureExpected;
|
|
||||||
import org.hibernate.testing.TestForIssue;
|
import org.hibernate.testing.TestForIssue;
|
||||||
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
|
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
|
||||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||||
|
@ -63,7 +62,6 @@ public class LazyToOnesProxyWithSubclassesTest extends BaseNonConfigCoreFunction
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@FailureExpected( jiraKey = "HHH-13640")
|
|
||||||
public void testNewProxyAssociation() {
|
public void testNewProxyAssociation() {
|
||||||
inTransaction(
|
inTransaction(
|
||||||
session -> {
|
session -> {
|
||||||
|
@ -87,7 +85,6 @@ public class LazyToOnesProxyWithSubclassesTest extends BaseNonConfigCoreFunction
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@FailureExpected( jiraKey = "HHH-13640")
|
|
||||||
public void testReusedProxyAssociation() {
|
public void testReusedProxyAssociation() {
|
||||||
inTransaction(
|
inTransaction(
|
||||||
session -> {
|
session -> {
|
||||||
|
|
Loading…
Reference in New Issue