HHH-9985 - bytecode enhancer - fix merge use case for composites

This commit is contained in:
barreiro 2015-07-27 06:14:22 +01:00 committed by Steve Ebersole
parent f759c152e2
commit 716e954f49
3 changed files with 21 additions and 3 deletions

View File

@ -415,6 +415,7 @@ public class DefaultMergeEventListener extends AbstractSaveEventListener impleme
final Object[] copiedValues = TypeHelper.replace( final Object[] copiedValues = TypeHelper.replace(
persister.getPropertyValues( entity ), persister.getPropertyValues( entity ),
persister.getPropertyValues( target ), persister.getPropertyValues( target ),
persister.getPropertyNames(),
persister.getPropertyTypes(), persister.getPropertyTypes(),
source, source,
target, target,
@ -452,6 +453,7 @@ public class DefaultMergeEventListener extends AbstractSaveEventListener impleme
copiedValues = TypeHelper.replace( copiedValues = TypeHelper.replace(
persister.getPropertyValues( entity ), persister.getPropertyValues( entity ),
persister.getPropertyValues( target ), persister.getPropertyValues( target ),
persister.getPropertyNames(),
persister.getPropertyTypes(), persister.getPropertyTypes(),
source, source,
target, target,

View File

@ -524,9 +524,10 @@ public class ComponentType extends AbstractType implements CompositeType, Proced
Object[] values = TypeHelper.replace( Object[] values = TypeHelper.replace(
getPropertyValues( original, entityMode ), getPropertyValues( original, entityMode ),
getPropertyValues( result, entityMode ), getPropertyValues( result, entityMode ),
propertyNames,
propertyTypes, propertyTypes,
session, session,
owner, result,
copyCache copyCache
); );
@ -556,9 +557,10 @@ public class ComponentType extends AbstractType implements CompositeType, Proced
Object[] values = TypeHelper.replace( Object[] values = TypeHelper.replace(
getPropertyValues( original, entityMode ), getPropertyValues( original, entityMode ),
getPropertyValues( result, entityMode ), getPropertyValues( result, entityMode ),
propertyNames,
propertyTypes, propertyTypes,
session, session,
owner, result,
copyCache, copyCache,
foreignKeyDirection foreignKeyDirection
); );

View File

@ -10,6 +10,8 @@ import java.io.Serializable;
import java.util.Map; import java.util.Map;
import org.hibernate.bytecode.instrumentation.spi.LazyPropertyInitializer; import org.hibernate.bytecode.instrumentation.spi.LazyPropertyInitializer;
import org.hibernate.engine.spi.CompositeOwner;
import org.hibernate.engine.spi.CompositeTracker;
import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.property.access.internal.PropertyAccessStrategyBackRefImpl; import org.hibernate.property.access.internal.PropertyAccessStrategyBackRefImpl;
import org.hibernate.tuple.NonIdentifierAttribute; import org.hibernate.tuple.NonIdentifierAttribute;
@ -147,6 +149,7 @@ public class TypeHelper {
public static Object[] replace( public static Object[] replace(
final Object[] original, final Object[] original,
final Object[] target, final Object[] target,
final String[] names,
final Type[] types, final Type[] types,
final SessionImplementor session, final SessionImplementor session,
final Object owner, final Object owner,
@ -176,6 +179,11 @@ public class TypeHelper {
else { else {
copied[i] = types[i].replace( original[i], target[i], session, owner, copyCache ); copied[i] = types[i].replace( original[i], target[i], session, owner, copyCache );
} }
// for bytecode enhanced entities, set the composite tracking structure
if ( copied[i] instanceof CompositeTracker && owner instanceof CompositeOwner ) {
( (CompositeTracker) copied[i] ).$$_hibernate_setOwner( names[i], (CompositeOwner) owner );
}
} }
return copied; return copied;
} }
@ -196,6 +204,7 @@ public class TypeHelper {
public static Object[] replace( public static Object[] replace(
final Object[] original, final Object[] original,
final Object[] target, final Object[] target,
final String[] names,
final Type[] types, final Type[] types,
final SessionImplementor session, final SessionImplementor session,
final Object owner, final Object owner,
@ -210,6 +219,11 @@ public class TypeHelper {
else { else {
copied[i] = types[i].replace( original[i], target[i], session, owner, copyCache, foreignKeyDirection ); copied[i] = types[i].replace( original[i], target[i], session, owner, copyCache, foreignKeyDirection );
} }
// for bytecode enhanced entities, set the composite tracking structure
if ( copied[i] instanceof CompositeTracker && owner instanceof CompositeOwner ) {
( (CompositeTracker) copied[i] ).$$_hibernate_setOwner( names[i], (CompositeOwner) owner );
}
} }
return copied; return copied;
} }