HHH-12406 : Add a test for HHH-11440

(cherry picked from commit 83e95d7681)
This commit is contained in:
Gail Badner 2018-03-19 18:06:32 -07:00
parent d2a796f04a
commit b41b861982
1 changed files with 48 additions and 0 deletions

View File

@ -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 {