Search in sources :

Example 71 with Property

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());
}
Also used : Property(org.hibernate.mapping.Property) PersistentClass(org.hibernate.mapping.PersistentClass)

Example 72 with Property

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());
}
Also used : Property(org.hibernate.mapping.Property) SimpleValue(org.hibernate.mapping.SimpleValue)

Example 73 with Property

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();
}
Also used : IndexedCollection(org.hibernate.mapping.IndexedCollection) Collection(org.hibernate.mapping.Collection) ElementCollection(javax.persistence.ElementCollection) Property(org.hibernate.mapping.Property) IndexedCollection(org.hibernate.mapping.IndexedCollection) PersistentClass(org.hibernate.mapping.PersistentClass) Session(org.hibernate.Session) Test(org.junit.Test)

Example 74 with Property

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);
    }
}
Also used : BasicType(org.hibernate.type.BasicType) AbstractStandardBasicType(org.hibernate.type.AbstractStandardBasicType) Type(org.hibernate.type.Type) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) MetadataSources(org.hibernate.boot.MetadataSources) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) AttributeConverterTypeAdapter(org.hibernate.type.descriptor.converter.AttributeConverterTypeAdapter) Property(org.hibernate.mapping.Property) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) PersistentClass(org.hibernate.mapping.PersistentClass) SimpleValue(org.hibernate.mapping.SimpleValue) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 75 with Property

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);
    }
}
Also used : BasicType(org.hibernate.type.BasicType) AbstractStandardBasicType(org.hibernate.type.AbstractStandardBasicType) Type(org.hibernate.type.Type) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) MetadataSources(org.hibernate.boot.MetadataSources) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) Property(org.hibernate.mapping.Property) AbstractStandardBasicType(org.hibernate.type.AbstractStandardBasicType) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) PersistentClass(org.hibernate.mapping.PersistentClass) SimpleValue(org.hibernate.mapping.SimpleValue) Test(org.junit.Test)

Aggregations

Property (org.hibernate.mapping.Property)94 PersistentClass (org.hibernate.mapping.PersistentClass)53 Component (org.hibernate.mapping.Component)30 Test (org.junit.Test)29 SimpleValue (org.hibernate.mapping.SimpleValue)24 Iterator (java.util.Iterator)23 SyntheticProperty (org.hibernate.mapping.SyntheticProperty)18 MetadataSources (org.hibernate.boot.MetadataSources)17 Column (org.hibernate.mapping.Column)17 AnnotationException (org.hibernate.AnnotationException)14 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)14 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)14 XProperty (org.hibernate.annotations.common.reflection.XProperty)12 Metadata (org.hibernate.boot.Metadata)11 Collection (org.hibernate.mapping.Collection)11 HashMap (java.util.HashMap)10 AssertionFailure (org.hibernate.AssertionFailure)10 MappingException (org.hibernate.MappingException)9 TestForIssue (org.hibernate.testing.TestForIssue)9 Map (java.util.Map)7