Search in sources :

Example 16 with StandardServiceRegistry

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

the class JoinColumnOverrideTest method testBlownPrecision.

@Test
@TestForIssue(jiraKey = "ANN-748")
public void testBlownPrecision() throws Exception {
    StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.DIALECT, "SQLServer").build();
    try {
        Metadata metadata = new MetadataSources(ssr).addAnnotatedClass(Bunny.class).addAnnotatedClass(PointyTooth.class).addAnnotatedClass(TwinkleToes.class).buildMetadata();
        boolean foundPointyToothCreate = false;
        boolean foundTwinkleToesCreate = false;
        List<String> commands = new SchemaCreatorImpl(ssr).generateCreationCommands(metadata, false);
        for (String command : commands) {
            log.debug(command);
            if (expectedSqlPointyTooth.equals(command)) {
                foundPointyToothCreate = true;
            } else if (expectedSqlTwinkleToes.equals(command)) {
                foundTwinkleToesCreate = true;
            }
        }
        assertTrue("Expected create table command for PointyTooth entity not found", foundPointyToothCreate);
        assertTrue("Expected create table command for TwinkleToes entity not found", foundTwinkleToesCreate);
    } finally {
        StandardServiceRegistryBuilder.destroy(ssr);
    }
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) SchemaCreatorImpl(org.hibernate.tool.schema.internal.SchemaCreatorImpl) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) TwinkleToes(org.hibernate.test.annotations.id.sequences.entities.TwinkleToes) Bunny(org.hibernate.test.annotations.id.sequences.entities.Bunny) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 17 with StandardServiceRegistry

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

the class DiscriminatorOptionsTest method testPropertyBasedDiscriminatorForcing.

@Test
public void testPropertyBasedDiscriminatorForcing() throws Exception {
    final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
    try {
        Metadata metadata = new MetadataSources(ssr).addAnnotatedClass(BaseClass2.class).addAnnotatedClass(SubClass2.class).getMetadataBuilder().enableImplicitForcingOfDiscriminatorsInSelect(true).build();
        PersistentClass persistentClass = metadata.getEntityBinding(BaseClass2.class.getName());
        assertNotNull(persistentClass);
        assertTrue(persistentClass instanceof RootClass);
        RootClass root = (RootClass) persistentClass;
        assertTrue("Discriminator should be forced by property", root.isForceDiscriminator());
    } finally {
        StandardServiceRegistryBuilder.destroy(ssr);
    }
}
Also used : RootClass(org.hibernate.mapping.RootClass) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) PersistentClass(org.hibernate.mapping.PersistentClass) Test(org.junit.Test)

Example 18 with StandardServiceRegistry

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

the class DuplicatedDiscriminatorValueTest method tryBuildingSessionFactory.

private void tryBuildingSessionFactory(Class... annotatedClasses) {
    final StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().build();
    try {
        final MetadataSources metadataSources = new MetadataSources(serviceRegistry);
        for (Class annotatedClass : annotatedClasses) {
            metadataSources.addAnnotatedClass(annotatedClass);
        }
        final Metadata metadata = metadataSources.buildMetadata();
        final SessionFactory sessionFactory = metadata.buildSessionFactory();
        sessionFactory.close();
    } finally {
        StandardServiceRegistryBuilder.destroy(serviceRegistry);
    }
}
Also used : SessionFactory(org.hibernate.SessionFactory) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) MetadataSources(org.hibernate.boot.MetadataSources) Metadata(org.hibernate.boot.Metadata) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry)

Example 19 with StandardServiceRegistry

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

the class CfgXmlParsingTest method testCfgXmlWithBadNamespaceAndSchemaLocation.

@Test(expected = ConfigurationException.class)
public void testCfgXmlWithBadNamespaceAndSchemaLocation() {
    StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().configure("org/hibernate/test/boot/cfgXml/badnamespace.cfg.xml").build();
    StandardServiceRegistryBuilder.destroy(ssr);
    fail("Expecting the bad namespace to fail");
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) Test(org.junit.Test)

Example 20 with StandardServiceRegistry

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

Aggregations

StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)169 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)152 Test (org.junit.Test)121 MetadataSources (org.hibernate.boot.MetadataSources)118 Metadata (org.hibernate.boot.Metadata)56 MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)39 PersistentClass (org.hibernate.mapping.PersistentClass)39 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)25 TestForIssue (org.hibernate.testing.TestForIssue)24 BootstrapServiceRegistryBuilder (org.hibernate.boot.registry.BootstrapServiceRegistryBuilder)23 Properties (java.util.Properties)20 BootstrapServiceRegistry (org.hibernate.boot.registry.BootstrapServiceRegistry)20 SchemaUpdate (org.hibernate.tool.hbm2ddl.SchemaUpdate)15 SessionFactory (org.hibernate.SessionFactory)14 Column (org.hibernate.mapping.Column)14 Property (org.hibernate.mapping.Property)14 Session (org.hibernate.Session)13 SchemaExport (org.hibernate.tool.hbm2ddl.SchemaExport)12 IdentifierGenerator (org.hibernate.id.IdentifierGenerator)11 RootClass (org.hibernate.mapping.RootClass)11