Search in sources :

Example 1 with ForeignKeyKey

use of org.hibernate.mapping.Table.ForeignKeyKey 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)

Aggregations

Map (java.util.Map)1 MetadataSources (org.hibernate.boot.MetadataSources)1 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)1 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)1 MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)1 ForeignKey (org.hibernate.mapping.ForeignKey)1 Table (org.hibernate.mapping.Table)1 ForeignKeyKey (org.hibernate.mapping.Table.ForeignKeyKey)1 TestForIssue (org.hibernate.testing.TestForIssue)1 SchemaExport (org.hibernate.tool.hbm2ddl.SchemaExport)1 Test (org.junit.Test)1