Search in sources :

Example 61 with SchemaExport

use of org.hibernate.tool.hbm2ddl.SchemaExport in project hibernate-orm by hibernate.

the class DisabledForeignKeyTest method basicTests.

@Test
@TestForIssue(jiraKey = "HHH-9704")
public void basicTests() {
    StandardServiceRegistryBuilder registryBuilder = new StandardServiceRegistryBuilder();
    StandardServiceRegistry standardRegistry = registryBuilder.build();
    try {
        final MetadataSources sources = new MetadataSources(standardRegistry);
        sources.addAnnotatedClass(ManyToManyOwner.class);
        sources.addAnnotatedClass(ManyToManyTarget.class);
        final MetadataImplementor metadata = (MetadataImplementor) sources.buildMetadata();
        metadata.validate();
        new SchemaExport().execute(EnumSet.of(TargetType.STDOUT), SchemaExport.Action.CREATE, metadata);
        int fkCount = 0;
        for (Table table : metadata.collectTableMappings()) {
            for (Map.Entry<ForeignKeyKey, ForeignKey> entry : table.getForeignKeys().entrySet()) {
                assertFalse("Creation for ForeignKey [" + entry.getKey() + "] was not disabled", entry.getValue().isCreationEnabled());
                fkCount++;
            }
        }
        // ultimately I want to actually create the ForeignKet reference, but simply disable its creation
        // via ForeignKet#disableCreation()
        assertEquals("Was expecting 4 FKs", 0, fkCount);
    } finally {
        StandardServiceRegistryBuilder.destroy(standardRegistry);
    }
}
Also used : ForeignKeyKey(org.hibernate.mapping.Table.ForeignKeyKey) Table(org.hibernate.mapping.Table) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) MetadataSources(org.hibernate.boot.MetadataSources) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) ForeignKey(org.hibernate.mapping.ForeignKey) Map(java.util.Map) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) SchemaExport(org.hibernate.tool.hbm2ddl.SchemaExport) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 62 with SchemaExport

use of org.hibernate.tool.hbm2ddl.SchemaExport in project hibernate-orm by hibernate.

the class CollectionJoinTableNamingTest method assertSameTableUsed.

private void assertSameTableUsed(Metadata metadata) {
    Collection inputs1Mapping = metadata.getCollectionBinding(Ptx.class.getName() + ".inputs1");
    assertEquals("ptx_input", inputs1Mapping.getCollectionTable().getName());
    Collection inputs2Mapping = metadata.getCollectionBinding(Ptx.class.getName() + ".inputs2");
    assertEquals("ptx_input", inputs2Mapping.getCollectionTable().getName());
    assertSame(inputs1Mapping.getCollectionTable(), inputs2Mapping.getCollectionTable());
    // NOTE : here so that tester can more easily see the produced table. It is only dumped to stdout
    new SchemaExport().create(EnumSet.of(TargetType.STDOUT), metadata);
    for (int i = 0; i < inputs1Mapping.getCollectionTable().getColumnSpan(); i++) {
        final Column column = inputs1Mapping.getCollectionTable().getColumn(i);
        // this, coupled with JPA saying the 2 collections implicitly map to the same table,
        // is the crux of the problem: all columns are null, so we effectively can never
        // insert rows into it.
        assertFalse(column.isNullable());
    }
}
Also used : Column(org.hibernate.mapping.Column) OrderColumn(javax.persistence.OrderColumn) Collection(org.hibernate.mapping.Collection) SchemaExport(org.hibernate.tool.hbm2ddl.SchemaExport)

Example 63 with SchemaExport

use of org.hibernate.tool.hbm2ddl.SchemaExport in project hibernate-orm by hibernate.

the class ColumnNamesTest method setUp.

@Before
public void setUp() throws IOException {
    ssr = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.KEYWORD_AUTO_QUOTING_ENABLED, "true").applySetting(AvailableSettings.HBM2DDL_JDBC_METADATA_EXTRACTOR_STRATEGY, jdbcMetadataExtractorStrategy).build();
    output = File.createTempFile("update_script", ".sql");
    output.deleteOnExit();
    metadata = new MetadataSources(ssr).addAnnotatedClass(Employee.class).buildMetadata();
    new SchemaExport().create(EnumSet.of(TargetType.DATABASE), metadata);
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) MetadataSources(org.hibernate.boot.MetadataSources) SchemaExport(org.hibernate.tool.hbm2ddl.SchemaExport) Before(org.junit.Before)

Example 64 with SchemaExport

use of org.hibernate.tool.hbm2ddl.SchemaExport in project hibernate-orm by hibernate.

the class MigrationTest method testSimpleColumnAddition.

@Test
public void testSimpleColumnAddition() {
    String resource1 = "org/hibernate/test/schemaupdate/1_Version.hbm.xml";
    String resource2 = "org/hibernate/test/schemaupdate/2_Version.hbm.xml";
    MetadataImplementor v1metadata = (MetadataImplementor) new MetadataSources(serviceRegistry).addResource(resource1).buildMetadata();
    new SchemaExport().drop(EnumSet.of(TargetType.DATABASE), v1metadata);
    final SchemaUpdate v1schemaUpdate = new SchemaUpdate();
    v1schemaUpdate.execute(EnumSet.of(TargetType.DATABASE, TargetType.STDOUT), v1metadata);
    assertEquals(0, v1schemaUpdate.getExceptions().size());
    MetadataImplementor v2metadata = (MetadataImplementor) new MetadataSources(serviceRegistry).addResource(resource2).buildMetadata();
    final SchemaUpdate v2schemaUpdate = new SchemaUpdate();
    v2schemaUpdate.execute(EnumSet.of(TargetType.DATABASE, TargetType.STDOUT), v2metadata);
    assertEquals(0, v2schemaUpdate.getExceptions().size());
    new SchemaExport().drop(EnumSet.of(TargetType.DATABASE), v2metadata);
}
Also used : MetadataSources(org.hibernate.boot.MetadataSources) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) SchemaUpdate(org.hibernate.tool.hbm2ddl.SchemaUpdate) SchemaExport(org.hibernate.tool.hbm2ddl.SchemaExport) Test(org.junit.Test)

Example 65 with SchemaExport

use of org.hibernate.tool.hbm2ddl.SchemaExport in project hibernate-orm by hibernate.

the class MigrationTest method testSameTableNameDifferentExplicitSchemas.

@Test
@TestForIssue(jiraKey = "HHH-9550")
public void testSameTableNameDifferentExplicitSchemas() {
    MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(serviceRegistry).addAnnotatedClass(CustomerInfo.class).addAnnotatedClass(PersonInfo.class).buildMetadata();
    // drop and then create the schema
    new SchemaExport().execute(EnumSet.of(TargetType.DATABASE), SchemaExport.Action.BOTH, metadata);
    try {
        // update the schema
        new SchemaUpdate().execute(EnumSet.of(TargetType.DATABASE), metadata);
    } finally {
        // drop the schema
        new SchemaExport().drop(EnumSet.of(TargetType.DATABASE), metadata);
    }
}
Also used : MetadataSources(org.hibernate.boot.MetadataSources) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) SchemaUpdate(org.hibernate.tool.hbm2ddl.SchemaUpdate) SchemaExport(org.hibernate.tool.hbm2ddl.SchemaExport) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Aggregations

SchemaExport (org.hibernate.tool.hbm2ddl.SchemaExport)90 Test (org.junit.Test)45 MetadataSources (org.hibernate.boot.MetadataSources)42 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)28 ISchemaExport (org.jboss.tools.hibernate.runtime.spi.ISchemaExport)27 MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)22 TestForIssue (org.hibernate.testing.TestForIssue)13 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)12 Configuration (org.hibernate.cfg.Configuration)12 Connection (java.sql.Connection)10 IConfiguration (org.jboss.tools.hibernate.runtime.spi.IConfiguration)10 After (org.junit.After)10 SchemaUpdate (org.hibernate.tool.hbm2ddl.SchemaUpdate)9 File (java.io.File)8 Before (org.junit.Before)8 HashMap (java.util.HashMap)5 Metadata (org.hibernate.boot.Metadata)5 IFacade (org.jboss.tools.hibernate.runtime.common.IFacade)5 SQLException (java.sql.SQLException)4 Entity (javax.persistence.Entity)4