Search in sources :

Example 41 with StandardServiceRegistryBuilder

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

the class Tests method testJpaJoinColumnPhysicalNaming.

@Test
@TestForIssue(jiraKey = "HHH-9961")
public void testJpaJoinColumnPhysicalNaming() {
    final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySettings(Environment.getProperties()).build();
    try {
        final MetadataSources metadataSources = new MetadataSources(ssr);
        metadataSources.addAnnotatedClass(Language.class);
        final MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder();
        metadataBuilder.applyImplicitNamingStrategy(ImplicitNamingStrategyJpaCompliantImpl.INSTANCE);
        metadataBuilder.applyPhysicalNamingStrategy(PhysicalNamingStrategyImpl.INSTANCE);
        final Metadata metadata = metadataBuilder.build();
        ((MetadataImplementor) metadata).validate();
        final PersistentClass languageBinding = metadata.getEntityBinding(Language.class.getName());
        final Property property = languageBinding.getProperty("fallBack");
        Iterator itr = property.getValue().getColumnIterator();
        assertTrue(itr.hasNext());
        final Column column = (Column) itr.next();
        assertFalse(itr.hasNext());
        assertEquals("C_FALLBACK_ID", column.getName().toUpperCase(Locale.ROOT));
    } finally {
        StandardServiceRegistryBuilder.destroy(ssr);
    }
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) MetadataBuilder(org.hibernate.boot.MetadataBuilder) Column(org.hibernate.mapping.Column) MetadataSources(org.hibernate.boot.MetadataSources) Metadata(org.hibernate.boot.Metadata) Iterator(java.util.Iterator) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) Property(org.hibernate.mapping.Property) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) PersistentClass(org.hibernate.mapping.PersistentClass) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 42 with StandardServiceRegistryBuilder

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

the class SimpleNationalizedTest method simpleNationalizedTest.

@Test
public void simpleNationalizedTest() {
    final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
    try {
        final MetadataSources ms = new MetadataSources(ssr);
        ms.addAnnotatedClass(NationalizedEntity.class);
        final Metadata metadata = ms.buildMetadata();
        PersistentClass pc = metadata.getEntityBinding(NationalizedEntity.class.getName());
        assertNotNull(pc);
        Property prop = pc.getProperty("nvarcharAtt");
        if (metadata.getDatabase().getDialect() instanceof PostgreSQL81Dialect) {
            // See issue HHH-10693
            assertSame(StringType.INSTANCE, prop.getType());
        } else {
            assertSame(StringNVarcharType.INSTANCE, prop.getType());
        }
        prop = pc.getProperty("materializedNclobAtt");
        if (metadata.getDatabase().getDialect() instanceof PostgreSQL81Dialect) {
            // See issue HHH-10693
            assertSame(MaterializedClobType.INSTANCE, prop.getType());
        } else {
            assertSame(MaterializedNClobType.INSTANCE, prop.getType());
        }
        prop = pc.getProperty("nclobAtt");
        assertSame(NClobType.INSTANCE, prop.getType());
        prop = pc.getProperty("nlongvarcharcharAtt");
        assertSame(NTextType.INSTANCE, prop.getType());
        prop = pc.getProperty("ncharArrAtt");
        if (metadata.getDatabase().getDialect() instanceof PostgreSQL81Dialect) {
            // See issue HHH-10693
            assertSame(CharacterArrayType.INSTANCE, prop.getType());
        } else {
            assertSame(StringNVarcharType.INSTANCE, prop.getType());
        }
        prop = pc.getProperty("ncharacterAtt");
        if (metadata.getDatabase().getDialect() instanceof PostgreSQL81Dialect) {
            // See issue HHH-10693
            assertSame(CharacterType.INSTANCE, prop.getType());
        } else {
            assertSame(CharacterNCharType.INSTANCE, prop.getType());
        }
    } finally {
        StandardServiceRegistryBuilder.destroy(ssr);
    }
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) MetadataSources(org.hibernate.boot.MetadataSources) Metadata(org.hibernate.boot.Metadata) Property(org.hibernate.mapping.Property) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) PersistentClass(org.hibernate.mapping.PersistentClass) PostgreSQL81Dialect(org.hibernate.dialect.PostgreSQL81Dialect) Test(org.junit.Test)

Example 43 with StandardServiceRegistryBuilder

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

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

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

Aggregations

StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)167 MetadataSources (org.hibernate.boot.MetadataSources)106 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)94 Test (org.junit.Test)92 Metadata (org.hibernate.boot.Metadata)46 MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)34 PersistentClass (org.hibernate.mapping.PersistentClass)27 Before (org.junit.Before)26 Properties (java.util.Properties)24 TestForIssue (org.hibernate.testing.TestForIssue)23 SchemaExport (org.hibernate.tool.hbm2ddl.SchemaExport)17 SessionFactory (org.hibernate.SessionFactory)15 BootstrapServiceRegistryBuilder (org.hibernate.boot.registry.BootstrapServiceRegistryBuilder)14 Property (org.hibernate.mapping.Property)14 SchemaUpdate (org.hibernate.tool.hbm2ddl.SchemaUpdate)14 File (java.io.File)13 BootstrapServiceRegistry (org.hibernate.boot.registry.BootstrapServiceRegistry)13 Map (java.util.Map)12 HashMap (java.util.HashMap)11 ServiceRegistry (org.hibernate.service.ServiceRegistry)11