use of org.hibernate.property.access.spi.SetterFieldImpl in project hibernate-orm by hibernate.
the class PropertyAccessEnhancedImpl method resolveEnhancedSetterForField.
private static Setter resolveEnhancedSetterForField(Class<?> containerClass, String propertyName, Field field) {
try {
String enhancedSetterName = EnhancerConstants.PERSISTENT_FIELD_WRITER_PREFIX + propertyName;
Method enhancedSetter = containerClass.getDeclaredMethod(enhancedSetterName, field.getType());
enhancedSetter.setAccessible(true);
return new EnhancedSetterImpl(containerClass, propertyName, enhancedSetter);
} catch (NoSuchMethodException e) {
// enhancedSetter = null --- field not enhanced: fallback to reflection using the field
return new SetterFieldImpl(containerClass, propertyName, field);
}
}
use of org.hibernate.property.access.spi.SetterFieldImpl in project hibernate-orm by hibernate.
the class GetterSetterSerializationTest method testPrivateFieldSetter.
@Test
@TestForIssue(jiraKey = "HHH-11202")
public void testPrivateFieldSetter() throws Exception {
AnEntity entity = new AnEntity(new PK(1L));
final Getter getter = new GetterFieldImpl(AnEntity.class, "pk", ReflectHelper.findField(AnEntity.class, "pk"));
final Setter setter = new SetterFieldImpl(AnEntity.class, "pk", ReflectHelper.findField(AnEntity.class, "pk"));
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(setter);
final ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
final Setter setterClone = (Setter) ois.readObject();
final PK pkNew = new PK(2L);
setterClone.set(entity, pkNew, null);
assertSame(pkNew, getter.get(entity));
}
Aggregations