HHH-7927 Enabling globally_quoted_identifiers breaks schema validation

if TableGenerator is used
This commit is contained in:
Brett Meyer 2013-10-31 07:01:22 -04:00
parent e1eef18d62
commit dd44ad459a
3 changed files with 33 additions and 1 deletions

View File

@ -1342,6 +1342,9 @@ public class Configuration implements Serializable {
while ( iter.hasNext() ) {
PersistentIdentifierGenerator generator = (PersistentIdentifierGenerator) iter.next();
Object key = generator.generatorKey();
if (key instanceof String) {
key = normalizer.normalizeIdentifierQuoting( (String) key );
}
if ( !databaseMetadata.isSequence( key ) && !databaseMetadata.isTable( key ) ) {
throw new HibernateException( "Missing sequence or table: " + key );
}

View File

@ -29,6 +29,12 @@ import static org.junit.Assert.fail;
import java.util.Iterator;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
@ -38,6 +44,8 @@ import org.hibernate.mapping.Table;
import org.hibernate.mapping.UniqueKey;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.hibernate.tool.hbm2ddl.SchemaExport;
import org.hibernate.tool.hbm2ddl.SchemaValidator;
import org.junit.Test;
/**
@ -86,6 +94,20 @@ public class QuoteGlobalTest extends BaseCoreFunctionalTestCase {
doTestHbmQuoting( AssociatedDataPoint.class );
}
@Test
@TestForIssue(jiraKey = "HHH-7927")
public void testTableGeneratorQuoting() {
Configuration configuration = constructAndConfigureConfiguration();
configuration.addAnnotatedClass(TestEntity.class);
new SchemaExport(configuration).execute( false, true, false, true );
try {
new SchemaValidator(configuration).validate();
}
catch (HibernateException e) {
fail( "The identifier generator table should have validated. " + e.getMessage() );
}
}
private void doTestHbmQuoting(Class clazz) {
Table table = configuration().getClassMapping( clazz.getName() ).getTable();
assertTrue( table.isQuoted() );
@ -117,4 +139,11 @@ public class QuoteGlobalTest extends BaseCoreFunctionalTestCase {
protected String[] getMappings() {
return new String[] { "quote/DataPoint.hbm.xml" };
}
@Entity
private static class TestEntity {
@Id
@GeneratedValue(strategy = GenerationType.TABLE)
private int id;
}
}

View File

@ -182,7 +182,7 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase {
return cfg;
}
private Configuration constructAndConfigureConfiguration() {
protected Configuration constructAndConfigureConfiguration() {
Configuration cfg = constructConfiguration();
configure( cfg );
return cfg;