From b41b861982e93eae5e0eb263263a77b774bcf58f Mon Sep 17 00:00:00 2001 From: Gail Badner Date: Mon, 19 Mar 2018 18:06:32 -0700 Subject: [PATCH] HHH-12406 : Add a test for HHH-11440 (cherry picked from commit 83e95d76816ccff30c9a7e64e318ee340d822ec4) --- .../SynonymValidationTest.java | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/hibernate-core/src/test/java/org/hibernate/test/schemavalidation/SynonymValidationTest.java b/hibernate-core/src/test/java/org/hibernate/test/schemavalidation/SynonymValidationTest.java index b1e0644011..8cc10a4682 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/schemavalidation/SynonymValidationTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/schemavalidation/SynonymValidationTest.java @@ -21,12 +21,15 @@ import org.hibernate.tool.hbm2ddl.SchemaValidator; import org.hibernate.tool.schema.JdbcMetadaAccessStrategy; import org.hibernate.testing.RequiresDialect; +import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; import org.hibernate.testing.transaction.TransactionUtil; import org.junit.After; import org.junit.Before; import org.junit.Test; +import static org.junit.Assert.assertEquals; + /** * Allows the BaseCoreFunctionalTestCase to create the schema using TestEntity. The test method validates against an * identical entity, but using the synonym name. @@ -80,6 +83,51 @@ public class SynonymValidationTest extends BaseNonConfigCoreFunctionalTestCase { } } + @Test + @TestForIssue( jiraKey = "HHH-12406") + public void testSynonymUsingDefaultStrategySchemaValidator() { + // Hibernate should use JdbcMetadaAccessStrategy.INDIVIDUALLY when + // AvailableSettings.ENABLE_SYNONYMS is true. + ssr = new StandardServiceRegistryBuilder() + .applySetting( AvailableSettings.ENABLE_SYNONYMS, "true" ) + .build(); + try { + final MetadataSources metadataSources = new MetadataSources( ssr ); + metadataSources.addAnnotatedClass( TestEntityWithSynonym.class ); + metadataSources.addAnnotatedClass( TestEntity.class ); + + new SchemaValidator().validate( metadataSources.buildMetadata() ); + } + finally { + StandardServiceRegistryBuilder.destroy( ssr ); + } + } + + @Test + @TestForIssue( jiraKey = "HHH-12406") + public void testSynonymUsingGroupedSchemaValidator() { + // Hibernate should use JdbcMetadaAccessStrategy.INDIVIDUALLY when + // AvailableSettings.ENABLE_SYNONYMS is true, + // even if JdbcMetadaAccessStrategy.GROUPED is specified. + ssr = new StandardServiceRegistryBuilder() + .applySetting( AvailableSettings.ENABLE_SYNONYMS, "true" ) + .applySetting( + AvailableSettings.HBM2DDL_JDBC_METADATA_EXTRACTOR_STRATEGY, + JdbcMetadaAccessStrategy.GROUPED + ) + .build(); + try { + final MetadataSources metadataSources = new MetadataSources( ssr ); + metadataSources.addAnnotatedClass( TestEntityWithSynonym.class ); + metadataSources.addAnnotatedClass( TestEntity.class ); + + new SchemaValidator().validate( metadataSources.buildMetadata() ); + } + finally { + StandardServiceRegistryBuilder.destroy( ssr ); + } + } + @Entity @Table(name = "test_entity") private static class TestEntity {