Search in sources :

Example 6 with BootstrapServiceRegistry

use of org.hibernate.boot.registry.BootstrapServiceRegistry 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 7 with BootstrapServiceRegistry

use of org.hibernate.boot.registry.BootstrapServiceRegistry 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)

Example 8 with BootstrapServiceRegistry

use of org.hibernate.boot.registry.BootstrapServiceRegistry in project hibernate-orm by hibernate.

the class CfgXmlResourceNameClosingTest method testStreamClosing.

@Test
public void testStreamClosing() {
    BootstrapServiceRegistry bsr = new BootstrapServiceRegistryBuilder().applyClassLoaderService(classLoaderService).build();
    StandardServiceRegistry ssr = new StandardServiceRegistryBuilder(bsr).configure("org/hibernate/test/boot/cfgXml/hibernate.cfg.xml").build();
    try {
        for (InputStreamWrapper openedStream : classLoaderService.openedStreams) {
            assertTrue(openedStream.wasClosed);
        }
    } finally {
        StandardServiceRegistryBuilder.destroy(ssr);
    }
    assertTrue(classLoaderService.stopped);
}
Also used : BootstrapServiceRegistryBuilder(org.hibernate.boot.registry.BootstrapServiceRegistryBuilder) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) BootstrapServiceRegistry(org.hibernate.boot.registry.BootstrapServiceRegistry) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) Test(org.junit.Test)

Example 9 with BootstrapServiceRegistry

use of org.hibernate.boot.registry.BootstrapServiceRegistry 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 10 with BootstrapServiceRegistry

use of org.hibernate.boot.registry.BootstrapServiceRegistry in project hibernate-orm by hibernate.

the class CollectionJoinTableNamingTest method testCollectionJoinTableNamingJpaCompliantStrategy.

@Test
@TestForIssue(jiraKey = "HHH-9908")
public void testCollectionJoinTableNamingJpaCompliantStrategy() {
    // Even in 4.3, with JPA compliant naming, Hibernate creates an unusable table...
    final MetadataSources metadataSources = new MetadataSources();
    try {
        metadataSources.addAnnotatedClass(Input.class);
        metadataSources.addAnnotatedClass(Ptx.class);
        final Metadata metadata = metadataSources.getMetadataBuilder().applyImplicitNamingStrategy(ImplicitNamingStrategyJpaCompliantImpl.INSTANCE).build();
        assertSameTableUsed(metadata);
    } finally {
        ServiceRegistry metaServiceRegistry = metadataSources.getServiceRegistry();
        if (metaServiceRegistry instanceof BootstrapServiceRegistry) {
            BootstrapServiceRegistryBuilder.destroy(metaServiceRegistry);
        }
    }
}
Also used : MetadataSources(org.hibernate.boot.MetadataSources) Metadata(org.hibernate.boot.Metadata) BootstrapServiceRegistry(org.hibernate.boot.registry.BootstrapServiceRegistry) ServiceRegistry(org.hibernate.service.ServiceRegistry) BootstrapServiceRegistry(org.hibernate.boot.registry.BootstrapServiceRegistry) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Aggregations

BootstrapServiceRegistry (org.hibernate.boot.registry.BootstrapServiceRegistry)26 Test (org.junit.Test)18 MetadataSources (org.hibernate.boot.MetadataSources)16 ServiceRegistry (org.hibernate.service.ServiceRegistry)14 BootstrapServiceRegistryBuilder (org.hibernate.boot.registry.BootstrapServiceRegistryBuilder)11 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)11 Metadata (org.hibernate.boot.Metadata)5 MappingException (org.hibernate.MappingException)4 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)4 TestForIssue (org.hibernate.testing.TestForIssue)4 FileInputStream (java.io.FileInputStream)3 Properties (java.util.Properties)3 AnnotationException (org.hibernate.AnnotationException)3 File (java.io.File)2 MetadataBuilder (org.hibernate.boot.MetadataBuilder)2 Configuration (org.hibernate.cfg.Configuration)2 Integrator (org.hibernate.integrator.spi.Integrator)2 InputStream (java.io.InputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 HashMap (java.util.HashMap)1