Search in sources :

Example 26 with MetadataSources

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

the class CollectionAsBasicTest method testCollectionAsBasic.

@Test
public void testCollectionAsBasic() {
    StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
    try {
        Metadata metadata = new MetadataSources(ssr).addAnnotatedClass(Post.class).getMetadataBuilder().applyBasicType(new DelimitedStringsType()).build();
        PersistentClass postBinding = metadata.getEntityBinding(Post.class.getName());
        Property tagsAttribute = postBinding.getProperty("tags");
    } finally {
        StandardServiceRegistryBuilder.destroy(ssr);
    }
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) Property(org.hibernate.mapping.Property) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) PersistentClass(org.hibernate.mapping.PersistentClass) Test(org.junit.Test)

Example 27 with MetadataSources

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

the class EnumeratedWithMappedSuperclassTest method testHHH10128.

@Test
public void testHHH10128() {
    final Metadata metadata = new MetadataSources(ssr).addAnnotatedClass(Entity.class).addAnnotatedClass(DescriptionEntity.class).addAnnotatedClass(AddressLevel.class).buildMetadata();
    final PersistentClass addressLevelBinding = metadata.getEntityBinding(AddressLevel.class.getName());
    final Property natureProperty = addressLevelBinding.getProperty("nature");
    CustomType customType = assertTyping(CustomType.class, natureProperty.getType());
    EnumType enumType = assertTyping(EnumType.class, customType.getUserType());
    assertEquals(Types.VARCHAR, enumType.sqlTypes()[0]);
    SessionFactoryImplementor sf = (SessionFactoryImplementor) metadata.buildSessionFactory();
    try {
        EntityPersister p = sf.getEntityPersister(AddressLevel.class.getName());
        CustomType runtimeType = assertTyping(CustomType.class, p.getPropertyType("nature"));
        EnumType runtimeEnumType = assertTyping(EnumType.class, runtimeType.getUserType());
        assertEquals(Types.VARCHAR, runtimeEnumType.sqlTypes()[0]);
    } finally {
        sf.close();
    }
}
Also used : CustomType(org.hibernate.type.CustomType) EntityPersister(org.hibernate.persister.entity.EntityPersister) EnumType(org.hibernate.type.EnumType) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) Property(org.hibernate.mapping.Property) PersistentClass(org.hibernate.mapping.PersistentClass) Test(org.junit.Test)

Example 28 with MetadataSources

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

the class OrmXmlEnumTypeTest method testOrmXmlDefinedEnumType.

@Test
public void testOrmXmlDefinedEnumType() {
    StandardServiceRegistry ssr = ServiceRegistryBuilder.buildServiceRegistry();
    try {
        MetadataSources ms = new MetadataSources(ssr);
        ms.addResource("org/hibernate/test/annotations/enumerated/ormXml/orm.xml");
        Metadata metadata = ms.buildMetadata();
        Type bindingPropertyType = metadata.getEntityBinding(BookWithOrmEnum.class.getName()).getProperty("bindingStringEnum").getType();
        CustomType customType = ExtraAssertions.assertTyping(CustomType.class, bindingPropertyType);
        EnumType enumType = ExtraAssertions.assertTyping(EnumType.class, customType.getUserType());
        assertFalse(enumType.isOrdinal());
    } finally {
        ServiceRegistryBuilder.destroy(ssr);
    }
}
Also used : CustomType(org.hibernate.type.CustomType) CustomType(org.hibernate.type.CustomType) EnumType(org.hibernate.type.EnumType) Type(org.hibernate.type.Type) EnumType(org.hibernate.type.EnumType) MetadataSources(org.hibernate.boot.MetadataSources) Metadata(org.hibernate.boot.Metadata) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) Test(org.junit.Test)

Example 29 with MetadataSources

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

the class FetchProfileTest method testWrongClass.

@Test
public void testWrongClass() {
    final MetadataSources metadataSources = new MetadataSources().addAnnotatedClass(Customer3.class).addAnnotatedClass(Order.class).addAnnotatedClass(Country.class);
    try {
        metadataSources.buildMetadata();
        fail();
    } catch (MappingException e) {
        log.trace("success");
    } finally {
        ServiceRegistry metaServiceRegistry = metadataSources.getServiceRegistry();
        if (metaServiceRegistry instanceof BootstrapServiceRegistry) {
            BootstrapServiceRegistryBuilder.destroy(metaServiceRegistry);
        }
    }
}
Also used : MetadataSources(org.hibernate.boot.MetadataSources) BootstrapServiceRegistry(org.hibernate.boot.registry.BootstrapServiceRegistry) ServiceRegistry(org.hibernate.service.ServiceRegistry) BootstrapServiceRegistry(org.hibernate.boot.registry.BootstrapServiceRegistry) MappingException(org.hibernate.MappingException) Test(org.junit.Test)

Example 30 with MetadataSources

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

the class FetchProfileTest method testUnsupportedFetchMode.

@Test
public void testUnsupportedFetchMode() {
    final MetadataSources metadataSources = new MetadataSources().addAnnotatedClass(Customer4.class).addAnnotatedClass(Order.class).addAnnotatedClass(Country.class);
    try {
        metadataSources.buildMetadata();
        fail();
    } catch (MappingException e) {
        log.trace("success");
    } finally {
        ServiceRegistry metaServiceRegistry = metadataSources.getServiceRegistry();
        if (metaServiceRegistry instanceof BootstrapServiceRegistry) {
            BootstrapServiceRegistryBuilder.destroy(metaServiceRegistry);
        }
    }
}
Also used : MetadataSources(org.hibernate.boot.MetadataSources) BootstrapServiceRegistry(org.hibernate.boot.registry.BootstrapServiceRegistry) ServiceRegistry(org.hibernate.service.ServiceRegistry) BootstrapServiceRegistry(org.hibernate.boot.registry.BootstrapServiceRegistry) MappingException(org.hibernate.MappingException) Test(org.junit.Test)

Aggregations

MetadataSources (org.hibernate.boot.MetadataSources)187 Test (org.junit.Test)133 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)104 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)30 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