From 55f7f71e04555f5f5a787161e145bda964033417 Mon Sep 17 00:00:00 2001 From: Gail Badner Date: Wed, 15 Feb 2017 17:31:27 -0800 Subject: [PATCH] HHH-10989 - Always resolve CollectionType on load so that unfetched collections have a reference stored in StatefulPersistentContext HHH-10989 : Shorten test table names --- .../engine/internal/TwoPhaseLoad.java | 22 +++++++++++++------ .../CascadeWithFkConstraintTestTask.java | 4 ++-- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/engine/internal/TwoPhaseLoad.java b/hibernate-core/src/main/java/org/hibernate/engine/internal/TwoPhaseLoad.java index 6406dde383..fa099e5a2f 100755 --- a/hibernate-core/src/main/java/org/hibernate/engine/internal/TwoPhaseLoad.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/internal/TwoPhaseLoad.java @@ -34,7 +34,6 @@ import org.hibernate.pretty.MessageHelper; import org.hibernate.property.access.internal.PropertyAccessStrategyBackRefImpl; import org.hibernate.proxy.HibernateProxy; -import org.hibernate.type.CollectionType; import org.hibernate.type.Type; import org.hibernate.type.TypeHelper; @@ -148,13 +147,22 @@ private static void doInitializeEntity( final Type[] types = persister.getPropertyTypes(); for ( int i = 0; i < hydratedState.length; i++ ) { final Object value = hydratedState[i]; - if ( value!=LazyPropertyInitializer.UNFETCHED_PROPERTY && value!= PropertyAccessStrategyBackRefImpl.UNKNOWN ) { - hydratedState[i] = types[i].resolve( value, session, entity ); + if ( value == LazyPropertyInitializer.UNFETCHED_PROPERTY ) { + // IMPLEMENTATION NOTE: This is a lazy property on a bytecode-enhanced entity. + // hydratedState[i] needs to remain LazyPropertyInitializer.UNFETCHED_PROPERTY so that + // setPropertyValues() below (ultimately AbstractEntityTuplizer#setPropertyValues) works properly + // No resolution is necessary, unless the lazy property is a collection. + if ( types[i].isCollectionType() ) { + // IMPLEMENTATION NOTE: this is a lazy collection property on a bytecode-enhanced entity. + // HHH-10989: We need to resolve the collection so that a CollectionReference is added to StatefulPersistentContext. + // As mentioned above, hydratedState[i] needs to remain LazyPropertyInitializer.UNFETCHED_PROPERTY + // so do not assign the resolved, unitialized PersistentCollection back to hydratedState[i]. + types[i].resolve( value, session, entity ); + } } - else if ( types[i].isCollectionType() ) { - // HHH-10989 Even if not fetched, resolve a collection so that a CollectionReference is added to StatefulPersistentContext - // No assignment to the hydratedState, that would trigger the load of the collection (below, on setPropertyValues) - types[i].resolve( value, session, entity ); + else if ( value!= PropertyAccessStrategyBackRefImpl.UNKNOWN ) { + // we know value != LazyPropertyInitializer.UNFETCHED_PROPERTY + hydratedState[i] = types[i].resolve( value, session, entity ); } } diff --git a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/cascade/CascadeWithFkConstraintTestTask.java b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/cascade/CascadeWithFkConstraintTestTask.java index 8cb6467f44..965aaf4ca1 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/cascade/CascadeWithFkConstraintTestTask.java +++ b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/cascade/CascadeWithFkConstraintTestTask.java @@ -100,7 +100,7 @@ protected void cleanup() { // --- // - @Entity + @Entity(name="Garage") public static class Garage { @Id @@ -120,7 +120,7 @@ public boolean insert(Car aCar) { } - @Entity + @Entity(name="Car") public static class Car { @Id