use of org.hibernate.property.access.spi.GetterFieldImpl 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));
}
use of org.hibernate.property.access.spi.GetterFieldImpl in project hibernate-orm by hibernate.
the class GetterSetterSerializationTest method testPrivateFieldGetter.
@Test
@TestForIssue(jiraKey = "HHH-11202")
public void testPrivateFieldGetter() throws Exception {
final AnEntity entity = new AnEntity(new PK(1L));
final Getter getter = new GetterFieldImpl(AnEntity.class, "pk", ReflectHelper.findField(AnEntity.class, "pk"));
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(getter);
final ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
final Getter getterClone = (Getter) ois.readObject();
assertSame(getter.get(entity), getterClone.get(entity));
}
use of org.hibernate.property.access.spi.GetterFieldImpl in project hibernate-orm by hibernate.
the class AccessMappingTest method testDefaultPropertyAccessIsInherited.
@Test
public void testDefaultPropertyAccessIsInherited() throws Exception {
Configuration cfg = new Configuration();
cfg.addAnnotatedClass(Horse.class);
cfg.addAnnotatedClass(Animal.class);
SessionFactoryImplementor factory = (SessionFactoryImplementor) cfg.buildSessionFactory(serviceRegistry);
try {
EntityTuplizer tuplizer = factory.getEntityPersister(Animal.class.getName()).getEntityMetamodel().getTuplizer();
assertTrue("Property access should be used since explicity configured via @Access", tuplizer.getIdentifierGetter() instanceof GetterMethodImpl);
tuplizer = factory.getEntityPersister(Horse.class.getName()).getEntityMetamodel().getTuplizer();
assertTrue("Field access should be used since the default access mode gets inherited", tuplizer.getGetter(0) instanceof GetterFieldImpl);
} finally {
factory.close();
}
}
use of org.hibernate.property.access.spi.GetterFieldImpl in project hibernate-orm by hibernate.
the class AccessMappingTest method testFieldAnnotationPlacement.
@Test
public void testFieldAnnotationPlacement() throws Exception {
Configuration cfg = new Configuration();
Class<?> classUnderTest = Course6.class;
cfg.addAnnotatedClass(classUnderTest);
cfg.addAnnotatedClass(Student.class);
SessionFactoryImplementor factory = (SessionFactoryImplementor) cfg.buildSessionFactory(serviceRegistry);
try {
EntityTuplizer tuplizer = factory.getEntityPersister(classUnderTest.getName()).getEntityMetamodel().getTuplizer();
assertTrue("Field access should be used.", tuplizer.getIdentifierGetter() instanceof GetterFieldImpl);
} finally {
factory.close();
}
}
use of org.hibernate.property.access.spi.GetterFieldImpl in project hibernate-orm by hibernate.
the class AccessMappingTest method testExplicitPropertyAccessAnnotationsWithHibernateStyleOverride.
@Test
public void testExplicitPropertyAccessAnnotationsWithHibernateStyleOverride() throws Exception {
Configuration cfg = new Configuration();
Class<?> classUnderTest = Course3.class;
cfg.addAnnotatedClass(classUnderTest);
cfg.addAnnotatedClass(Student.class);
SessionFactoryImplementor factory = (SessionFactoryImplementor) cfg.buildSessionFactory(serviceRegistry);
try {
EntityTuplizer tuplizer = factory.getEntityPersister(classUnderTest.getName()).getEntityMetamodel().getTuplizer();
assertTrue("Field access should be used.", tuplizer.getIdentifierGetter() instanceof GetterFieldImpl);
assertTrue("Property access should be used.", tuplizer.getGetter(0) instanceof GetterMethodImpl);
} finally {
factory.close();
}
}
Aggregations