Search in sources :

Example 36 with MetadataSources

use of org.hibernate.boot.MetadataSources in project hibernate-orm by hibernate.

the class ParameterizedAttributeConverterParameterTypeTest method testNestedTypeParameterAutoApplication.

@Test
@TestForIssue(jiraKey = "HHH-10050")
public void testNestedTypeParameterAutoApplication() {
    final Metadata metadata = new MetadataSources(ssr).addAnnotatedClass(SampleEntity.class).getMetadataBuilder().applyAttributeConverter(IntegerListConverter.class).applyAttributeConverter(StringListConverter.class).build();
    // lets make sure the auto-apply converters were applied properly...
    PersistentClass pc = metadata.getEntityBinding(SampleEntity.class.getName());
    {
        Property prop = pc.getProperty("someStrings");
        AttributeConverterTypeAdapter type = assertTyping(AttributeConverterTypeAdapter.class, prop.getType());
        assertTyping(StringListConverter.class, type.getAttributeConverter());
    }
    {
        Property prop = pc.getProperty("someIntegers");
        AttributeConverterTypeAdapter type = assertTyping(AttributeConverterTypeAdapter.class, prop.getType());
        assertTyping(IntegerListConverter.class, type.getAttributeConverter());
    }
}
Also used : Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) AttributeConverterTypeAdapter(org.hibernate.type.descriptor.converter.AttributeConverterTypeAdapter) Property(org.hibernate.mapping.Property) PersistentClass(org.hibernate.mapping.PersistentClass) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 37 with MetadataSources

use of org.hibernate.boot.MetadataSources in project hibernate-orm by hibernate.

the class SimpleXmlOverriddenTest method baseline.

/**
	 * A baseline test, with an explicit @Convert annotation that should be in effect
	 */
@Test
public void baseline() {
    Metadata metadata = new MetadataSources(ssr).addAnnotatedClass(TheEntity.class).buildMetadata();
    PersistentClass pc = metadata.getEntityBinding(TheEntity.class.getName());
    Type type = pc.getProperty("it").getType();
    AttributeConverterTypeAdapter adapter = assertTyping(AttributeConverterTypeAdapter.class, type);
    assertTyping(SillyStringConverter.class, adapter.getAttributeConverter());
}
Also used : StringType(org.hibernate.type.StringType) Type(org.hibernate.type.Type) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) AttributeConverterTypeAdapter(org.hibernate.type.descriptor.converter.AttributeConverterTypeAdapter) PersistentClass(org.hibernate.mapping.PersistentClass) Test(org.junit.Test)

Example 38 with MetadataSources

use of org.hibernate.boot.MetadataSources in project hibernate-orm by hibernate.

the class SimpleXmlOverriddenTest method testDefinitionAtAttributeLevel.

/**
	 * Test outcome of applying overrides via orm.xml, specifically at the attribute level
	 */
@Test
public void testDefinitionAtAttributeLevel() {
    // NOTE : simple-override.xml applied disable-conversion="true" at the attribute-level
    Metadata metadata = new MetadataSources(ssr).addAnnotatedClass(TheEntity.class).addResource("org/hibernate/test/converter/simple-override.xml").buildMetadata();
    PersistentClass pc = metadata.getEntityBinding(TheEntity.class.getName());
    Type type = pc.getProperty("it").getType();
    assertTyping(StringType.class, type);
}
Also used : StringType(org.hibernate.type.StringType) Type(org.hibernate.type.Type) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) PersistentClass(org.hibernate.mapping.PersistentClass) Test(org.junit.Test)

Example 39 with MetadataSources

use of org.hibernate.boot.MetadataSources in project hibernate-orm by hibernate.

the class InvalidEnumeratedJavaTypeTest method testInvalidMapping.

@Test
public void testInvalidMapping() {
    MetadataSources metadataSources = new MetadataSources().addAnnotatedClass(TheEntity.class);
    try {
        metadataSources.buildMetadata();
        fail("Was expecting failure");
    } catch (AnnotationException ignore) {
    } finally {
        ServiceRegistry metaServiceRegistry = metadataSources.getServiceRegistry();
        if (metaServiceRegistry instanceof BootstrapServiceRegistry) {
            BootstrapServiceRegistryBuilder.destroy(metaServiceRegistry);
        }
    }
}
Also used : MetadataSources(org.hibernate.boot.MetadataSources) AnnotationException(org.hibernate.AnnotationException) BootstrapServiceRegistry(org.hibernate.boot.registry.BootstrapServiceRegistry) ServiceRegistry(org.hibernate.service.ServiceRegistry) BootstrapServiceRegistry(org.hibernate.boot.registry.BootstrapServiceRegistry) Test(org.junit.Test)

Example 40 with MetadataSources

use of org.hibernate.boot.MetadataSources in project hibernate-orm by hibernate.

the class ExtendsTest method testMissingSuper.

@Test
public void testMissingSuper() {
    try {
        Metadata metadata = new MetadataSources(serviceRegistry).addResource(getBaseForMappings() + "extendshbm/Customer.hbm.xml").addResource(getBaseForMappings() + "extendshbm/Employee.hbm.xml").buildMetadata();
        fail("Should not be able to build sessionFactory without a Person");
    } catch (HibernateException e) {
    }
}
Also used : HibernateException(org.hibernate.HibernateException) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) Test(org.junit.Test)

Aggregations

MetadataSources (org.hibernate.boot.MetadataSources)189 Test (org.junit.Test)133 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)105 Metadata (org.hibernate.boot.Metadata)87 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)73 MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)58 TestForIssue (org.hibernate.testing.TestForIssue)47 PersistentClass (org.hibernate.mapping.PersistentClass)36 SchemaExport (org.hibernate.tool.hbm2ddl.SchemaExport)31 SchemaUpdate (org.hibernate.tool.hbm2ddl.SchemaUpdate)19 BootstrapServiceRegistry (org.hibernate.boot.registry.BootstrapServiceRegistry)18 ServiceRegistry (org.hibernate.service.ServiceRegistry)18 Before (org.junit.Before)18 Property (org.hibernate.mapping.Property)17 File (java.io.File)14 SchemaCreatorImpl (org.hibernate.tool.schema.internal.SchemaCreatorImpl)14 Map (java.util.Map)13 MetadataBuilder (org.hibernate.boot.MetadataBuilder)12 Type (org.hibernate.type.Type)12 SimpleValue (org.hibernate.mapping.SimpleValue)11