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 ecbcf02bfe..e47d7bb8d2 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/Configuration.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/Configuration.java @@ -1545,15 +1545,14 @@ public class Configuration implements Serializable { Set unboundNoLogical = new HashSet(); for ( int index = 0; index < size; index++ ) { String column = columnNames[index]; - final String logicalColumnName = StringHelper.isNotEmpty( column ) ? normalizer.normalizeIdentifierQuoting( column ) : ""; try { - final String columnName = createMappings().getPhysicalColumnName( logicalColumnName, table ); + final String columnName = createMappings().getPhysicalColumnName( column, table ); columns[index] = new Column( columnName ); unbound.add( columns[index] ); //column equals and hashcode is based on column name } catch ( MappingException e ) { - unboundNoLogical.add( new Column( logicalColumnName ) ); + unboundNoLogical.add( new Column( column ) ); } } UniqueKey uk = table.getOrCreateUniqueKey( keyName ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/quote/Person.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/quote/Person.java new file mode 100644 index 0000000000..0705a3117b --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/quote/Person.java @@ -0,0 +1,56 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * JBoss, Home of Professional Open Source + * Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors + * as indicated by the @authors tag. All rights reserved. + * See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU Lesser General Public License, v. 2.1. + * This program is distributed in the hope that it will be useful, but WITHOUT A + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License, + * v.2.1 along with this distribution; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ +package org.hibernate.test.annotations.quote; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Table; +import javax.persistence.UniqueConstraint; + +/** + * @author Brett Meyer + */ +@Entity +@Table(uniqueConstraints = { @UniqueConstraint(columnNames = { "name" }) }) +public class Person { + @Id + @GeneratedValue + private long id; + + private String name; + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} \ No newline at end of file diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/quote/QuoteGlobalTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/quote/QuoteGlobalTest.java index e0887a9e41..23fecfbc72 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/quote/QuoteGlobalTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/quote/QuoteGlobalTest.java @@ -23,20 +23,40 @@ */ package org.hibernate.test.annotations.quote; -import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +import java.util.Iterator; import org.hibernate.Session; import org.hibernate.Transaction; import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Environment; +import org.hibernate.mapping.UniqueKey; +import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; - -import static org.junit.Assert.assertEquals; +import org.junit.Test; /** * @author Emmanuel Bernard + * @author Brett Meyer */ public class QuoteGlobalTest extends BaseCoreFunctionalTestCase { + + @Test + @TestForIssue(jiraKey = "HHH-7890") + public void testQuotedUniqueConstraint() { + Iterator itr = configuration().getClassMapping( Person.class.getName() ) + .getTable().getUniqueKeyIterator(); + while ( itr.hasNext() ) { + UniqueKey uk = itr.next(); + assertEquals( uk.getColumns().size(), 1 ); + assertEquals( uk.getColumn( 0 ).getName(), "name"); + return; + } + fail( "GLOBALLY_QUOTED_IDENTIFIERS caused the unique key creation to fail." ); + } + @Test public void testQuoteManytoMany() { Session s = openSession(); @@ -67,7 +87,8 @@ public class QuoteGlobalTest extends BaseCoreFunctionalTestCase { return new Class[] { User.class, Role.class, - Phone.class + Phone.class, + Person.class }; } }