Search in sources :

Example 36 with SimpleValue

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

the class NestedEmbeddableMetadataTest method testEnumTypeInterpretation.

@Test
public void testEnumTypeInterpretation() {
    final StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().enableAutoClose().applySetting(AvailableSettings.HBM2DDL_AUTO, "create-drop").build();
    try {
        final Metadata metadata = new MetadataSources(serviceRegistry).addAnnotatedClass(Customer.class).buildMetadata();
        PersistentClass classMetadata = metadata.getEntityBinding(Customer.class.getName());
        Property investmentsProperty = classMetadata.getProperty("investments");
        Collection investmentsValue = (Collection) investmentsProperty.getValue();
        Component investmentMetadata = (Component) investmentsValue.getElement();
        Value descriptionValue = investmentMetadata.getProperty("description").getValue();
        assertEquals(1, descriptionValue.getColumnSpan());
        Column selectable = (Column) descriptionValue.getColumnIterator().next();
        assertEquals(500, selectable.getLength());
        Component amountMetadata = (Component) investmentMetadata.getProperty("amount").getValue();
        SimpleValue currencyMetadata = (SimpleValue) amountMetadata.getProperty("currency").getValue();
        CustomType currencyType = (CustomType) currencyMetadata.getType();
        int[] currencySqlTypes = currencyType.sqlTypes(metadata);
        assertEquals(1, currencySqlTypes.length);
        assertJdbcTypeCode(Types.VARCHAR, currencySqlTypes[0]);
    } finally {
        StandardServiceRegistryBuilder.destroy(serviceRegistry);
    }
}
Also used : CustomType(org.hibernate.type.CustomType) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) SimpleValue(org.hibernate.mapping.SimpleValue) Column(org.hibernate.mapping.Column) SimpleValue(org.hibernate.mapping.SimpleValue) Value(org.hibernate.mapping.Value) Collection(org.hibernate.mapping.Collection) Component(org.hibernate.mapping.Component) Property(org.hibernate.mapping.Property) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) PersistentClass(org.hibernate.mapping.PersistentClass) Test(org.junit.Test)

Example 37 with SimpleValue

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

the class FieldAccessedNestedEmbeddableMetadataTest method testEnumTypeInterpretation.

@Test
@FailureExpected(jiraKey = "HHH-9089")
public void testEnumTypeInterpretation() {
    StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
    try {
        final Metadata metadata = new MetadataSources(ssr).addAnnotatedClass(Customer.class).buildMetadata();
        PersistentClass classMetadata = metadata.getEntityBinding(Customer.class.getName());
        Property investmentsProperty = classMetadata.getProperty("investments");
        Collection investmentsValue = (Collection) investmentsProperty.getValue();
        Component investmentMetadata = (Component) investmentsValue.getElement();
        Value descriptionValue = investmentMetadata.getProperty("description").getValue();
        assertEquals(1, descriptionValue.getColumnSpan());
        Column selectable = (Column) descriptionValue.getColumnIterator().next();
        assertEquals(500, selectable.getLength());
        Component amountMetadata = (Component) investmentMetadata.getProperty("amount").getValue();
        SimpleValue currencyMetadata = (SimpleValue) amountMetadata.getProperty("currency").getValue();
        CustomType currencyType = (CustomType) currencyMetadata.getType();
        int[] currencySqlTypes = currencyType.sqlTypes(metadata);
        assertEquals(1, currencySqlTypes.length);
        assertJdbcTypeCode(Types.VARCHAR, currencySqlTypes[0]);
    } finally {
        StandardServiceRegistryBuilder.destroy(ssr);
    }
}
Also used : CustomType(org.hibernate.type.CustomType) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) SimpleValue(org.hibernate.mapping.SimpleValue) Column(org.hibernate.mapping.Column) SimpleValue(org.hibernate.mapping.SimpleValue) Value(org.hibernate.mapping.Value) Collection(org.hibernate.mapping.Collection) Component(org.hibernate.mapping.Component) Property(org.hibernate.mapping.Property) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) PersistentClass(org.hibernate.mapping.PersistentClass) Test(org.junit.Test) FailureExpected(org.hibernate.testing.FailureExpected)

Example 38 with SimpleValue

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

the class ComponentNamingStrategyTest method testComponentSafeNamingStrategy.

@Test
@TestForIssue(jiraKey = "HHH-6005")
public void testComponentSafeNamingStrategy() {
    final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
    try {
        final MetadataSources ms = new MetadataSources(ssr);
        ms.addAnnotatedClass(Container.class).addAnnotatedClass(Item.class);
        final Metadata metadata = ms.getMetadataBuilder().applyImplicitNamingStrategy(ImplicitNamingStrategyComponentPathImpl.INSTANCE).build();
        final PersistentClass pc = metadata.getEntityBinding(Container.class.getName());
        Property p = pc.getProperty("items");
        Bag value = assertTyping(Bag.class, p.getValue());
        SimpleValue elementValue = assertTyping(SimpleValue.class, value.getElement());
        assertEquals(1, elementValue.getColumnSpan());
        Column column = assertTyping(Column.class, elementValue.getColumnIterator().next());
        assertEquals("items_name", column.getName());
    } finally {
        StandardServiceRegistryBuilder.destroy(ssr);
    }
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) Column(org.hibernate.mapping.Column) MetadataSources(org.hibernate.boot.MetadataSources) Metadata(org.hibernate.boot.Metadata) Bag(org.hibernate.mapping.Bag) 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 39 with SimpleValue

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

the class ComponentNamingStrategyTest method testDefaultNamingStrategy.

@Test
public void testDefaultNamingStrategy() {
    final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
    try {
        final MetadataSources ms = new MetadataSources(ssr);
        ms.addAnnotatedClass(Container.class).addAnnotatedClass(Item.class);
        final Metadata metadata = ms.getMetadataBuilder().applyImplicitNamingStrategy(ImplicitNamingStrategyJpaCompliantImpl.INSTANCE).build();
        final PersistentClass pc = metadata.getEntityBinding(Container.class.getName());
        Property p = pc.getProperty("items");
        Bag value = assertTyping(Bag.class, p.getValue());
        SimpleValue elementValue = assertTyping(SimpleValue.class, value.getElement());
        assertEquals(1, elementValue.getColumnSpan());
        Column column = assertTyping(Column.class, elementValue.getColumnIterator().next());
        assertEquals(column.getName(), "name");
    } finally {
        StandardServiceRegistryBuilder.destroy(ssr);
    }
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) Column(org.hibernate.mapping.Column) MetadataSources(org.hibernate.boot.MetadataSources) Metadata(org.hibernate.boot.Metadata) Bag(org.hibernate.mapping.Bag) 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)

Example 40 with SimpleValue

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

the class EntityBinder method setFKNameIfDefined.

private void setFKNameIfDefined(Join join) {
    // just awful..
    org.hibernate.annotations.Table matchingTable = findMatchingComplimentTableAnnotation(join);
    if (matchingTable != null && !BinderHelper.isEmptyAnnotationValue(matchingTable.foreignKey().name())) {
        ((SimpleValue) join.getKey()).setForeignKeyName(matchingTable.foreignKey().name());
    } else {
        javax.persistence.SecondaryTable jpaSecondaryTable = findMatchingSecondaryTable(join);
        if (jpaSecondaryTable != null) {
            if (jpaSecondaryTable.foreignKey().value() == ConstraintMode.NO_CONSTRAINT) {
                ((SimpleValue) join.getKey()).setForeignKeyName("none");
            } else {
                ((SimpleValue) join.getKey()).setForeignKeyName(StringHelper.nullIfEmpty(jpaSecondaryTable.foreignKey().name()));
                ((SimpleValue) join.getKey()).setForeignKeyDefinition(StringHelper.nullIfEmpty(jpaSecondaryTable.foreignKey().foreignKeyDefinition()));
            }
        }
    }
}
Also used : SecondaryTable(javax.persistence.SecondaryTable) SimpleValue(org.hibernate.mapping.SimpleValue)

Aggregations

SimpleValue (org.hibernate.mapping.SimpleValue)42 Property (org.hibernate.mapping.Property)23 PersistentClass (org.hibernate.mapping.PersistentClass)18 Column (org.hibernate.mapping.Column)13 Test (org.junit.Test)12 AnnotationException (org.hibernate.AnnotationException)11 MetadataSources (org.hibernate.boot.MetadataSources)11 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)10 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)10 Identifier (org.hibernate.boot.model.naming.Identifier)9 Component (org.hibernate.mapping.Component)8 DependantValue (org.hibernate.mapping.DependantValue)8 BasicType (org.hibernate.type.BasicType)8 LocalMetadataBuildingContext (org.hibernate.boot.model.source.spi.LocalMetadataBuildingContext)7 MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)7 Table (org.hibernate.mapping.Table)7 RootClass (org.hibernate.mapping.RootClass)6 AssertionFailure (org.hibernate.AssertionFailure)5 Collection (org.hibernate.mapping.Collection)5 ManyToOne (org.hibernate.mapping.ManyToOne)5