HHH-13948 - EnhancedSetterImpl should define writeReplace
This commit is contained in:
parent
2a4c10a663
commit
2ddf58907e
|
@ -6,14 +6,16 @@
|
|||
*/
|
||||
package org.hibernate.property.access.spi;
|
||||
|
||||
import org.hibernate.bytecode.enhance.spi.interceptor.LazyAttributeLoadingInterceptor;
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import org.hibernate.bytecode.enhance.spi.interceptor.BytecodeLazyAttributeInterceptor;
|
||||
import org.hibernate.engine.spi.CompositeOwner;
|
||||
import org.hibernate.engine.spi.CompositeTracker;
|
||||
import org.hibernate.engine.spi.PersistentAttributeInterceptable;
|
||||
import org.hibernate.engine.spi.PersistentAttributeInterceptor;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import org.hibernate.property.access.internal.AbstractFieldSerialForm;
|
||||
|
||||
/**
|
||||
* A specialized Setter implementation for handling setting values into
|
||||
|
@ -25,9 +27,9 @@ import java.lang.reflect.Field;
|
|||
* @author Luis Barreiro
|
||||
*/
|
||||
public class EnhancedSetterImpl extends SetterFieldImpl {
|
||||
|
||||
private final String propertyName;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public EnhancedSetterImpl(Class containerClass, String propertyName, Field field) {
|
||||
super( containerClass, propertyName, field );
|
||||
this.propertyName = propertyName;
|
||||
|
@ -46,9 +48,34 @@ public class EnhancedSetterImpl extends SetterFieldImpl {
|
|||
// This marks the attribute as initialized, so it doesn't get lazy loaded afterwards
|
||||
if ( target instanceof PersistentAttributeInterceptable ) {
|
||||
PersistentAttributeInterceptor interceptor = ( (PersistentAttributeInterceptable) target ).$$_hibernate_getInterceptor();
|
||||
if ( interceptor != null && interceptor instanceof LazyAttributeLoadingInterceptor ) {
|
||||
interceptor.attributeInitialized( propertyName );
|
||||
if ( interceptor instanceof BytecodeLazyAttributeInterceptor ) {
|
||||
( (BytecodeLazyAttributeInterceptor) interceptor ).attributeInitialized( propertyName );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// serialization
|
||||
|
||||
private Object writeReplace() {
|
||||
return new SerialForm( getContainerClass(), propertyName, getField() );
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private static class SerialForm extends AbstractFieldSerialForm implements Serializable {
|
||||
private final Class containerClass;
|
||||
private final String propertyName;
|
||||
|
||||
|
||||
private SerialForm(Class containerClass, String propertyName, Field field) {
|
||||
super( field );
|
||||
this.containerClass = containerClass;
|
||||
this.propertyName = propertyName;
|
||||
}
|
||||
|
||||
private Object readResolve() {
|
||||
return new EnhancedSetterImpl( containerClass, propertyName, resolveField() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
*/
|
||||
package org.hibernate.property.access.spi;
|
||||
|
||||
import java.io.ObjectStreamException;
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
|
@ -35,6 +34,18 @@ public class SetterFieldImpl implements Setter {
|
|||
this.setterMethod = ReflectHelper.setterMethodOrNull( containerClass, propertyName, field.getType() );
|
||||
}
|
||||
|
||||
public Class getContainerClass() {
|
||||
return containerClass;
|
||||
}
|
||||
|
||||
public String getPropertyName() {
|
||||
return propertyName;
|
||||
}
|
||||
|
||||
protected Field getField() {
|
||||
return field;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(Object target, Object value, SessionFactoryImplementor factory) {
|
||||
try {
|
||||
|
|
Loading…
Reference in New Issue