From b76f8c20656ad554f2dedc4e6116ca77845b87f2 Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Mon, 6 Jun 2016 16:51:02 +0100 Subject: [PATCH] HHH-10802 - Add test for issue --- .../CrossSchemaForeignKeyGenerationTest.java | 33 +++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/foreignkeys/crossschema/CrossSchemaForeignKeyGenerationTest.java b/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/foreignkeys/crossschema/CrossSchemaForeignKeyGenerationTest.java index 8932824e17..0c00e1cc0e 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/foreignkeys/crossschema/CrossSchemaForeignKeyGenerationTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/foreignkeys/crossschema/CrossSchemaForeignKeyGenerationTest.java @@ -19,10 +19,12 @@ import org.hibernate.boot.model.relational.Database; import org.hibernate.boot.registry.StandardServiceRegistry; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.boot.spi.MetadataImplementor; +import org.hibernate.cfg.AvailableSettings; import org.hibernate.engine.config.spi.ConfigurationService; import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; import org.hibernate.engine.jdbc.spi.JdbcServices; import org.hibernate.tool.hbm2ddl.SchemaExport; +import org.hibernate.tool.hbm2ddl.SchemaUpdate; import org.hibernate.tool.schema.SourceType; import org.hibernate.tool.schema.TargetType; import org.hibernate.tool.schema.extract.internal.DatabaseInformationImpl; @@ -61,7 +63,8 @@ public class CrossSchemaForeignKeyGenerationTest extends BaseUnitTestCase { public void setUp() throws IOException { output = File.createTempFile( "update_script", ".sql" ); output.deleteOnExit(); - ssr = new StandardServiceRegistryBuilder().build(); + ssr = new StandardServiceRegistryBuilder().applySetting( AvailableSettings.HBM2DLL_CREATE_SCHEMAS, "true" ) + .build(); } @After @@ -92,6 +95,32 @@ public class CrossSchemaForeignKeyGenerationTest extends BaseUnitTestCase { ); } + @Test + @TestForIssue(jiraKey = "HHH-10802") + public void testSchemaUpdateDoesNotFailResolvingCrossSchemaForeignKey() throws Exception { + final MetadataSources metadataSources = new MetadataSources( ssr ); + metadataSources.addAnnotatedClass( SchemaOneEntity.class ); + metadataSources.addAnnotatedClass( SchemaTwoEntity.class ); + + MetadataImplementor metadata = (MetadataImplementor) metadataSources.buildMetadata(); + metadata.validate(); + + new SchemaExport() + .setOutputFile( output.getAbsolutePath() ) + .setFormat( false ) + .create( EnumSet.of( TargetType.DATABASE ), metadata ); + + new SchemaUpdate().setHaltOnError( true ) + .setOutputFile( output.getAbsolutePath() ) + .setFormat( false ) + .execute( EnumSet.of( TargetType.DATABASE ), metadata ); + + new SchemaExport().setHaltOnError( true ) + .setOutputFile( output.getAbsolutePath() ) + .setFormat( false ) + .drop( EnumSet.of( TargetType.DATABASE ), metadata ); + } + @Test @TestForIssue(jiraKey = "HHH-10420") public void testSchemaMigrationForeignKeysAreGeneratedAfterAllTheTablesAreCreated() throws Exception { @@ -178,6 +207,4 @@ public class CrossSchemaForeignKeyGenerationTest extends BaseUnitTestCase { new TargetDatabaseImpl( ssr.getService( JdbcServices.class ).getBootstrapJdbcConnectionAccess() ) }; } - - }