Skip to content

Commit

Permalink
HHH-10989 - Always resolve CollectionType on load so that unfetched c…
Browse files Browse the repository at this point in the history
…ollections have a reference stored in StatefulPersistentContext

HHH-10989 : Shorten test table names

(cherry picked from commit 55f7f71)
  • Loading branch information
gbadner committed Feb 22, 2017
1 parent 6569161 commit e44b0cc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
Expand Up @@ -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;

Expand Down Expand Up @@ -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 );
}
}

Expand Down
Expand Up @@ -100,7 +100,7 @@ protected void cleanup() {

// --- //

@Entity
@Entity(name="Garage")
public static class Garage {

@Id
Expand All @@ -120,7 +120,7 @@ public boolean insert(Car aCar) {

}

@Entity
@Entity(name="Car")
public static class Car {

@Id
Expand Down

0 comments on commit e44b0cc

Please sign in to comment.