diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/Configuration.java b/hibernate-core/src/main/java/org/hibernate/cfg/Configuration.java index c8f94727eb..883d19fe51 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/Configuration.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/Configuration.java @@ -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 ); } diff --git a/hibernate-core/src/test/java/org/hibernate/test/quote/QuoteGlobalTest.java b/hibernate-core/src/test/java/org/hibernate/test/quote/QuoteGlobalTest.java index 2e7f602cc5..3c31ecd111 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/quote/QuoteGlobalTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/quote/QuoteGlobalTest.java @@ -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; /** @@ -85,6 +93,20 @@ public class QuoteGlobalTest extends BaseCoreFunctionalTestCase { doTestHbmQuoting( DataPoint.class ); 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(); @@ -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; + } } diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseCoreFunctionalTestCase.java b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseCoreFunctionalTestCase.java index b82b4c8018..6b38bbcf8b 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseCoreFunctionalTestCase.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseCoreFunctionalTestCase.java @@ -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;