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(
persister.getPropertyValues( entity ),
persister.getPropertyValues( target ),
persister.getPropertyNames(),
persister.getPropertyTypes(),
source,
target,
@ -452,6 +453,7 @@ public class DefaultMergeEventListener extends AbstractSaveEventListener impleme
copiedValues = TypeHelper.replace(
persister.getPropertyValues( entity ),
persister.getPropertyValues( target ),
persister.getPropertyNames(),
persister.getPropertyTypes(),
source,
target,

View File

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

View File

@ -10,6 +10,8 @@ import java.io.Serializable;
import java.util.Map;
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.property.access.internal.PropertyAccessStrategyBackRefImpl;
import org.hibernate.tuple.NonIdentifierAttribute;
@ -147,6 +149,7 @@ public class TypeHelper {
public static Object[] replace(
final Object[] original,
final Object[] target,
final String[] names,
final Type[] types,
final SessionImplementor session,
final Object owner,
@ -176,6 +179,11 @@ public class TypeHelper {
else {
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;
}
@ -196,6 +204,7 @@ public class TypeHelper {
public static Object[] replace(
final Object[] original,
final Object[] target,
final String[] names,
final Type[] types,
final SessionImplementor session,
final Object owner,
@ -204,12 +213,17 @@ public class TypeHelper {
Object[] copied = new Object[original.length];
for ( int i = 0; i < types.length; i++ ) {
if ( original[i] == LazyPropertyInitializer.UNFETCHED_PROPERTY
|| original[i] == PropertyAccessStrategyBackRefImpl.UNKNOWN ) {
|| original[i] == PropertyAccessStrategyBackRefImpl.UNKNOWN ) {
copied[i] = target[i];
}
else {
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;
}