HHH-7890 Quoting identifiers breaks @UniqueConstraint
This commit is contained in:
parent
ad6c4d06b0
commit
9684a0afa5
|
@ -1545,15 +1545,14 @@ public class Configuration implements Serializable {
|
|||
Set<Column> unboundNoLogical = new HashSet<Column>();
|
||||
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 );
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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<UniqueKey> 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
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue