use of org.hibernate.mapping.Property in project hibernate-orm by hibernate.
the class TimestampTest method assertTimestampSource.
private void assertTimestampSource(Class<?> clazz, Class<?> expectedTypeClass) throws Exception {
PersistentClass persistentClass = metadata.getEntityBinding(clazz.getName());
assertNotNull(persistentClass);
Property versionProperty = persistentClass.getVersion();
assertNotNull(versionProperty);
assertEquals("Wrong timestamp type", expectedTypeClass, versionProperty.getType().getClass());
}
use of org.hibernate.mapping.Property in project hibernate-orm by hibernate.
the class CollectionCompositeElementExplicitConversionTest method checkComposite.
private void checkComposite(Component composite) throws Exception {
// check `eyeColor`
final Property eyeColorProperty = composite.getProperty("eyeColor");
final SimpleValue eyeColorValueMapping = (SimpleValue) eyeColorProperty.getValue();
assertThat(simpleValueAttributeConverterDescriptorField.get(eyeColorValueMapping), CoreMatchers.notNullValue());
// check `hairColor`
final Property hairColorProperty = composite.getProperty("hairColor");
final SimpleValue hairColorValueMapping = (SimpleValue) hairColorProperty.getValue();
assertThat(simpleValueAttributeConverterDescriptorField.get(hairColorValueMapping), CoreMatchers.notNullValue());
}
use of org.hibernate.mapping.Property in project hibernate-orm by hibernate.
the class ElementCollectionTests method testSimpleConvertUsage.
@Test
public void testSimpleConvertUsage() throws MalformedURLException {
// first some assertions of the metamodel
PersistentClass entityBinding = metadata().getEntityBinding(TheEntity.class.getName());
assertNotNull(entityBinding);
Property setAttributeBinding = entityBinding.getProperty("set");
Collection setBinding = (Collection) setAttributeBinding.getValue();
assertTyping(AttributeConverterTypeAdapter.class, setBinding.getElement().getType());
Property mapAttributeBinding = entityBinding.getProperty("map");
IndexedCollection mapBinding = (IndexedCollection) mapAttributeBinding.getValue();
assertTyping(AttributeConverterTypeAdapter.class, mapBinding.getIndex().getType());
assertTyping(AttributeConverterTypeAdapter.class, mapBinding.getElement().getType());
// now lets try to use the model, integration-testing-style!
TheEntity entity = new TheEntity(1);
Session s = openSession();
s.beginTransaction();
s.save(entity);
s.getTransaction().commit();
s.close();
s = openSession();
s.beginTransaction();
TheEntity retrieved = (TheEntity) s.load(TheEntity.class, 1);
assertEquals(1, retrieved.getSet().size());
assertEquals(new ValueType("set_value"), retrieved.getSet().iterator().next());
assertEquals(1, retrieved.getMap().size());
assertEquals(new ValueType("map_value"), retrieved.getMap().get(new ValueType("map_key")));
s.delete(retrieved);
s.getTransaction().commit();
s.close();
}
use of org.hibernate.mapping.Property in project hibernate-orm by hibernate.
the class AttributeConverterTest method testBasicOrmXmlConverterApplication.
@Test
@TestForIssue(jiraKey = "HHH-8462")
public void testBasicOrmXmlConverterApplication() {
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
try {
MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).addAnnotatedClass(Tester.class).addURL(ConfigHelper.findAsResource("org/hibernate/test/converter/orm.xml")).getMetadataBuilder().build();
PersistentClass tester = metadata.getEntityBinding(Tester.class.getName());
Property nameProp = tester.getProperty("name");
SimpleValue nameValue = (SimpleValue) nameProp.getValue();
Type type = nameValue.getType();
assertNotNull(type);
if (!AttributeConverterTypeAdapter.class.isInstance(type)) {
fail("AttributeConverter not applied");
}
AttributeConverterTypeAdapter basicType = assertTyping(AttributeConverterTypeAdapter.class, type);
assertSame(StringTypeDescriptor.INSTANCE, basicType.getJavaTypeDescriptor());
assertEquals(Types.CLOB, basicType.getSqlTypeDescriptor().getSqlType());
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.mapping.Property in project hibernate-orm by hibernate.
the class AttributeConverterTest method testBasicConverterDisableApplication.
@Test
public void testBasicConverterDisableApplication() {
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
try {
MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).addAnnotatedClass(Tester2.class).getMetadataBuilder().applyAttributeConverter(StringClobConverter.class, true).build();
PersistentClass tester = metadata.getEntityBinding(Tester2.class.getName());
Property nameProp = tester.getProperty("name");
SimpleValue nameValue = (SimpleValue) nameProp.getValue();
Type type = nameValue.getType();
assertNotNull(type);
if (AttributeConverterTypeAdapter.class.isInstance(type)) {
fail("AttributeConverter applied (should not have been)");
}
AbstractStandardBasicType basicType = assertTyping(AbstractStandardBasicType.class, type);
assertSame(StringTypeDescriptor.INSTANCE, basicType.getJavaTypeDescriptor());
assertEquals(Types.VARCHAR, basicType.getSqlTypeDescriptor().getSqlType());
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
Aggregations