Search in sources :

Example 36 with StandardServiceRegistry

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

the class OneToOneSchemaTest method testUniqueKeyNotGeneratedViaAnnotations.

@Test
public void testUniqueKeyNotGeneratedViaAnnotations() throws Exception {
    StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
    try {
        Metadata metadata = new MetadataSources(ssr).addAnnotatedClass(Parent.class).addAnnotatedClass(Child.class).buildMetadata();
        Table childTable = metadata.getDatabase().getDefaultNamespace().locateTable(Identifier.toIdentifier("CHILD"));
        assertFalse("UniqueKey was generated when it should not", childTable.getUniqueKeyIterator().hasNext());
    } finally {
        StandardServiceRegistryBuilder.destroy(ssr);
    }
}
Also used : Table(org.hibernate.mapping.Table) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) Test(org.junit.Test)

Example 37 with StandardServiceRegistry

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

the class SchemaUpdateSchemaNameTest method cleanup.

@After
public void cleanup() {
    // Drops the table after the sql alter test.
    StandardServiceRegistry ssr = null;
    try {
        // build simple configuration
        final Configuration cfg = buildConfiguration(SimpleFirst.class);
        // Build Standard Service Registry
        ssr = new StandardServiceRegistryBuilder(new BootstrapServiceRegistryBuilder().build(), cfg.getStandardServiceRegistryBuilder().getAggregatedCfgXml()).applySettings(cfg.getProperties()).build();
        SessionFactory sf = cfg.buildSessionFactory(ssr);
        try {
            Session session = sf.openSession();
            try {
                session.getTransaction().begin();
                session.createNativeQuery("DROP TABLE Simple").executeUpdate();
                session.getTransaction().commit();
            } catch (Throwable t) {
                if (session.getTransaction().isActive()) {
                    session.getTransaction().rollback();
                }
                throw t;
            } finally {
                session.close();
            }
        } finally {
            sf.close();
        }
    } finally {
        StandardServiceRegistryBuilder.destroy(ssr);
    }
}
Also used : SessionFactory(org.hibernate.SessionFactory) BootstrapServiceRegistryBuilder(org.hibernate.boot.registry.BootstrapServiceRegistryBuilder) Configuration(org.hibernate.cfg.Configuration) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) Session(org.hibernate.Session) After(org.junit.After)

Example 38 with StandardServiceRegistry

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

the class SchemaUpdateSchemaNameTest method testSqlAlterWithTableSchemaName.

@Test
public void testSqlAlterWithTableSchemaName() throws Exception {
    StandardServiceRegistry ssr = null;
    try {
        final Configuration cfg = buildConfiguration(SimpleNext.class);
        ssr = new StandardServiceRegistryBuilder(new BootstrapServiceRegistryBuilder().build(), cfg.getStandardServiceRegistryBuilder().getAggregatedCfgXml()).applySettings(cfg.getProperties()).build();
        SessionFactory sf = cfg.buildSessionFactory(ssr);
        try {
            Session session = sf.openSession();
            try {
                session.getTransaction().begin();
                session.createQuery("FROM Simple", SimpleNext.class).getResultList();
                session.getTransaction().commit();
            } catch (Throwable t) {
                if (session.getTransaction().isActive()) {
                    session.getTransaction().rollback();
                }
                throw t;
            } finally {
                session.close();
            }
        } finally {
            sf.close();
        }
    } finally {
        StandardServiceRegistryBuilder.destroy(ssr);
    }
}
Also used : SessionFactory(org.hibernate.SessionFactory) BootstrapServiceRegistryBuilder(org.hibernate.boot.registry.BootstrapServiceRegistryBuilder) Configuration(org.hibernate.cfg.Configuration) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) Session(org.hibernate.Session) Test(org.junit.Test)

Example 39 with StandardServiceRegistry

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

the class SequenceReadingTest method testSequenceReading.

@Test
public void testSequenceReading() {
    StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.DIALECT, MyExtendedH2Dialect.class).build();
    try {
        final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).addAnnotatedClass(MyEntity.class).buildMetadata();
        metadata.validate();
        try {
            // try to update the schema
            new SchemaUpdate().execute(EnumSet.of(TargetType.DATABASE), metadata);
        } finally {
            try {
                // clean up
                new SchemaExport().drop(EnumSet.of(TargetType.DATABASE), metadata);
            } catch (Exception ignore) {
            }
        }
    } finally {
        StandardServiceRegistryBuilder.destroy(ssr);
    }
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) MetadataSources(org.hibernate.boot.MetadataSources) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) SchemaUpdate(org.hibernate.tool.hbm2ddl.SchemaUpdate) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) SchemaExport(org.hibernate.tool.hbm2ddl.SchemaExport) Test(org.junit.Test)

Example 40 with StandardServiceRegistry

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

the class SchemaUpdateSchemaNameTest method buildInitialSchema.

@Before
public void buildInitialSchema() throws Exception {
    // Builds the initial table in the schema.
    StandardServiceRegistry ssr = null;
    try {
        final Configuration cfg = buildConfiguration(SimpleFirst.class);
        ssr = new StandardServiceRegistryBuilder(new BootstrapServiceRegistryBuilder().build(), cfg.getStandardServiceRegistryBuilder().getAggregatedCfgXml()).applySettings(cfg.getProperties()).build();
        cfg.buildSessionFactory(ssr).close();
    } finally {
        StandardServiceRegistryBuilder.destroy(ssr);
    }
}
Also used : BootstrapServiceRegistryBuilder(org.hibernate.boot.registry.BootstrapServiceRegistryBuilder) Configuration(org.hibernate.cfg.Configuration) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) Before(org.junit.Before)

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