HHH-11418 - SynonymValidationTest failure
This commit is contained in:
parent
50ee618f1e
commit
b19d76f2cc
|
@ -31,6 +31,9 @@ import org.junit.Test;
|
|||
* Allows the BaseCoreFunctionalTestCase to create the schema using TestEntity. The test method validates against an
|
||||
* identical entity, but using the synonym name.
|
||||
*
|
||||
* When SYNONYM are used, the GROUPED Strategy cannot be applied because when the tableNamePattern was not provided
|
||||
* java.sql.DatabaseMetaData#getColumns(...) Oracle implementation returns only the columns related with the synonym
|
||||
*
|
||||
* @author Brett Meyer
|
||||
*/
|
||||
@RequiresDialect(Oracle9iDialect.class)
|
||||
|
@ -79,28 +82,13 @@ public class SynonymValidationTest extends BaseNonConfigCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSynonymUsingImprovedSchemaValidar() {
|
||||
public void testSynonymUsingIndividuallySchemaValidator() {
|
||||
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 );
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSynonymUsingSchemaValidator() {
|
||||
ssr = new StandardServiceRegistryBuilder()
|
||||
.applySetting( AvailableSettings.ENABLE_SYNONYMS, "true" )
|
||||
.applySetting( AvailableSettings.HBM2DDL_JDBC_METADATA_EXTRACTOR_STRATEGY, JdbcMetadaAccessStrategy.GROUPED )
|
||||
.applySetting(
|
||||
AvailableSettings.HBM2DDL_JDBC_METADATA_EXTRACTOR_STRATEGY,
|
||||
JdbcMetadaAccessStrategy.INDIVIDUALLY
|
||||
)
|
||||
.build();
|
||||
try {
|
||||
final MetadataSources metadataSources = new MetadataSources( ssr );
|
||||
|
|
|
@ -0,0 +1,199 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.schemavalidation;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.boot.MetadataSources;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.dialect.H2Dialect;
|
||||
import org.hibernate.dialect.PostgreSQL81Dialect;
|
||||
import org.hibernate.tool.hbm2ddl.SchemaValidator;
|
||||
import org.hibernate.tool.schema.JdbcMetadaAccessStrategy;
|
||||
|
||||
import org.hibernate.testing.RequiresDialect;
|
||||
import org.hibernate.testing.RequiresDialects;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Andrea Boriero
|
||||
*/
|
||||
@RequiresDialects({
|
||||
@RequiresDialect(PostgreSQL81Dialect.class),
|
||||
@RequiresDialect(H2Dialect.class)
|
||||
})
|
||||
public class ViewValidationTest extends BaseCoreFunctionalTestCase {
|
||||
private StandardServiceRegistry ssr;
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class<?>[] {TestEntity.class};
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
Session s = openSession();
|
||||
try {
|
||||
s.getTransaction().begin();
|
||||
s.createSQLQuery( "CREATE VIEW test_synonym AS SELECT * FROM test_entity" ).executeUpdate();
|
||||
s.getTransaction().commit();
|
||||
}
|
||||
catch (Exception e) {
|
||||
if ( s.getTransaction().isActive() ) {
|
||||
s.getTransaction().rollback();
|
||||
}
|
||||
}
|
||||
finally {
|
||||
s.close();
|
||||
}
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
Session s = openSession();
|
||||
try {
|
||||
s.getTransaction().begin();
|
||||
s.createSQLQuery( "DROP VIEW test_synonym CASCADE" ).executeUpdate();
|
||||
s.getTransaction().commit();
|
||||
}
|
||||
catch (Exception e) {
|
||||
if ( s.getTransaction().isActive() ) {
|
||||
s.getTransaction().rollback();
|
||||
}
|
||||
}
|
||||
finally {
|
||||
s.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSynonymUsingGroupedSchemaValidator() {
|
||||
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 );
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSynonymUsingIndividuallySchemaValidator() {
|
||||
ssr = new StandardServiceRegistryBuilder()
|
||||
.applySetting( AvailableSettings.ENABLE_SYNONYMS, "true" )
|
||||
.applySetting(
|
||||
AvailableSettings.HBM2DDL_JDBC_METADATA_EXTRACTOR_STRATEGY,
|
||||
JdbcMetadaAccessStrategy.INDIVIDUALLY
|
||||
)
|
||||
.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 {
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Long id;
|
||||
|
||||
@Column(nullable = false)
|
||||
private String key;
|
||||
|
||||
private String value;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
@Entity
|
||||
@Table(name = "test_synonym")
|
||||
private static class TestEntityWithSynonym {
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Long id;
|
||||
|
||||
@Column(nullable = false)
|
||||
private String key;
|
||||
|
||||
private String value;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue