Search in sources :

Example 31 with Property

use of org.hibernate.mapping.Property in project hibernate-orm by hibernate.

the class Tests method testJpaJoinColumnPhysicalNaming.

@Test
@TestForIssue(jiraKey = "HHH-9961")
public void testJpaJoinColumnPhysicalNaming() {
    final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySettings(Environment.getProperties()).build();
    try {
        final MetadataSources metadataSources = new MetadataSources(ssr);
        metadataSources.addAnnotatedClass(Language.class);
        final MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder();
        metadataBuilder.applyImplicitNamingStrategy(ImplicitNamingStrategyJpaCompliantImpl.INSTANCE);
        metadataBuilder.applyPhysicalNamingStrategy(PhysicalNamingStrategyImpl.INSTANCE);
        final Metadata metadata = metadataBuilder.build();
        ((MetadataImplementor) metadata).validate();
        final PersistentClass languageBinding = metadata.getEntityBinding(Language.class.getName());
        final Property property = languageBinding.getProperty("fallBack");
        Iterator itr = property.getValue().getColumnIterator();
        assertTrue(itr.hasNext());
        final Column column = (Column) itr.next();
        assertFalse(itr.hasNext());
        assertEquals("C_FALLBACK_ID", column.getName().toUpperCase(Locale.ROOT));
    } finally {
        StandardServiceRegistryBuilder.destroy(ssr);
    }
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) MetadataBuilder(org.hibernate.boot.MetadataBuilder) Column(org.hibernate.mapping.Column) MetadataSources(org.hibernate.boot.MetadataSources) Metadata(org.hibernate.boot.Metadata) Iterator(java.util.Iterator) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) Property(org.hibernate.mapping.Property) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) PersistentClass(org.hibernate.mapping.PersistentClass) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 32 with Property

use of org.hibernate.mapping.Property in project hibernate-orm by hibernate.

the class SimpleNationalizedTest method simpleNationalizedTest.

@Test
public void simpleNationalizedTest() {
    final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
    try {
        final MetadataSources ms = new MetadataSources(ssr);
        ms.addAnnotatedClass(NationalizedEntity.class);
        final Metadata metadata = ms.buildMetadata();
        PersistentClass pc = metadata.getEntityBinding(NationalizedEntity.class.getName());
        assertNotNull(pc);
        Property prop = pc.getProperty("nvarcharAtt");
        if (metadata.getDatabase().getDialect() instanceof PostgreSQL81Dialect) {
            // See issue HHH-10693
            assertSame(StringType.INSTANCE, prop.getType());
        } else {
            assertSame(StringNVarcharType.INSTANCE, prop.getType());
        }
        prop = pc.getProperty("materializedNclobAtt");
        if (metadata.getDatabase().getDialect() instanceof PostgreSQL81Dialect) {
            // See issue HHH-10693
            assertSame(MaterializedClobType.INSTANCE, prop.getType());
        } else {
            assertSame(MaterializedNClobType.INSTANCE, prop.getType());
        }
        prop = pc.getProperty("nclobAtt");
        assertSame(NClobType.INSTANCE, prop.getType());
        prop = pc.getProperty("nlongvarcharcharAtt");
        assertSame(NTextType.INSTANCE, prop.getType());
        prop = pc.getProperty("ncharArrAtt");
        if (metadata.getDatabase().getDialect() instanceof PostgreSQL81Dialect) {
            // See issue HHH-10693
            assertSame(CharacterArrayType.INSTANCE, prop.getType());
        } else {
            assertSame(StringNVarcharType.INSTANCE, prop.getType());
        }
        prop = pc.getProperty("ncharacterAtt");
        if (metadata.getDatabase().getDialect() instanceof PostgreSQL81Dialect) {
            // See issue HHH-10693
            assertSame(CharacterType.INSTANCE, prop.getType());
        } else {
            assertSame(CharacterNCharType.INSTANCE, prop.getType());
        }
    } finally {
        StandardServiceRegistryBuilder.destroy(ssr);
    }
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) MetadataSources(org.hibernate.boot.MetadataSources) Metadata(org.hibernate.boot.Metadata) Property(org.hibernate.mapping.Property) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) PersistentClass(org.hibernate.mapping.PersistentClass) PostgreSQL81Dialect(org.hibernate.dialect.PostgreSQL81Dialect) Test(org.junit.Test)

Example 33 with Property

use of org.hibernate.mapping.Property in project hibernate-orm by hibernate.

the class BaseNamingTests method validateZipCode.

protected void validateZipCode(Metadata metadata) {
    final PersistentClass zipCodeBinding = metadata.getEntityBinding(ZipCode.class.getName());
    assertNotNull(zipCodeBinding);
    validateZipCodePrimaryTableName(zipCodeBinding.getTable().getQuotedName());
    assertEquals(1, zipCodeBinding.getIdentifier().getColumnSpan());
    validateZipCodePrimaryKeyColumn((Column) zipCodeBinding.getIdentifier().getColumnIterator().next());
    final Property codeBinding = zipCodeBinding.getProperty("code");
    assertNotNull(codeBinding);
    assertEquals(1, codeBinding.getColumnSpan());
    validateZipCodeCodeColumn((Column) codeBinding.getColumnIterator().next());
    final Property cityBinding = zipCodeBinding.getProperty("city");
    assertNotNull(cityBinding);
    assertEquals(1, cityBinding.getColumnSpan());
    validateZipCodeCityColumn((Column) cityBinding.getColumnIterator().next());
    final Property stateBinding = zipCodeBinding.getProperty("state");
    assertNotNull(stateBinding);
    assertEquals(1, stateBinding.getColumnSpan());
    validateZipCodeStateColumn((Column) stateBinding.getColumnIterator().next());
}
Also used : Property(org.hibernate.mapping.Property) PersistentClass(org.hibernate.mapping.PersistentClass)

Example 34 with Property

use of org.hibernate.mapping.Property in project hibernate-orm by hibernate.

the class BaseNamingTests method validateOrder.

protected void validateOrder(Metadata metadata) {
    final PersistentClass orderBinding = metadata.getEntityBinding(Order.class.getName());
    assertNotNull(orderBinding);
    validateOrderPrimaryTableName(orderBinding.getTable().getQuotedName());
    assertEquals(1, orderBinding.getIdentifier().getColumnSpan());
    validateOrderPrimaryKeyColumn((Column) orderBinding.getIdentifier().getColumnIterator().next());
    final Property referenceCodeBinding = orderBinding.getProperty("referenceCode");
    assertNotNull(referenceCodeBinding);
    assertEquals(1, referenceCodeBinding.getColumnSpan());
    validateOrderReferenceCodeColumn((Column) referenceCodeBinding.getColumnIterator().next());
    final Property placedBinding = orderBinding.getProperty("placed");
    assertNotNull(placedBinding);
    assertEquals(1, placedBinding.getColumnSpan());
    validateOrderPlacedColumn((Column) placedBinding.getColumnIterator().next());
    final Property fulfilledBinding = orderBinding.getProperty("fulfilled");
    assertNotNull(fulfilledBinding);
    assertEquals(1, fulfilledBinding.getColumnSpan());
    validateOrderFulfilledColumn((Column) fulfilledBinding.getColumnIterator().next());
    final Property customerBinding = orderBinding.getProperty("customer");
    assertNotNull(customerBinding);
    assertEquals(1, customerBinding.getColumnSpan());
    validateOrderCustomerColumn((Column) customerBinding.getColumnIterator().next());
}
Also used : Property(org.hibernate.mapping.Property) PersistentClass(org.hibernate.mapping.PersistentClass)

Example 35 with Property

use of org.hibernate.mapping.Property in project hibernate-orm by hibernate.

the class PersistentClassTest method testGetProperty.

@Test
public void testGetProperty() {
    RootClass pc = new RootClass(metadataBuildingContext);
    Property p = new Property();
    p.setName("name");
    pc.addProperty(p);
    Assert.assertEquals(p, pc.getProperty("name"));
    Assert.assertEquals(p, pc.getProperty("name.test"));
    try {
        Assert.assertNull(pc.getProperty("test"));
        Assert.fail("MappingException expected");
    } catch (MappingException e) {
    // expected
    }
}
Also used : RootClass(org.hibernate.mapping.RootClass) Property(org.hibernate.mapping.Property) MappingException(org.hibernate.MappingException) 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