HHH-8102 : Generated foreign key export identifiers can collide

This commit is contained in:
Gail Badner 2013-03-21 12:56:38 -07:00
parent 5348367665
commit 5edee45ff7
1 changed files with 46 additions and 0 deletions

View File

@ -23,6 +23,11 @@
*/
package org.hibernate.metamodel.spi.relational;
import junit.framework.Assert;
import org.junit.Test;
import org.hibernate.testing.FailureExpectedWithNewMetamodel;
/**
* @author Gail Badner
*/
@ -35,4 +40,45 @@ public class ForeignKeyConstraintNameTests extends AbstractConstraintNameTests {
referencedTable.getPrimaryKey().addColumn( referencedTable.locateColumn( COLUMN_NAMES[0] ) );
return table.createForeignKey( referencedTable, constraintName );
}
@Test
@FailureExpectedWithNewMetamodel
public void testGeneratedExportedIdentifier(){
testExportedIdentifier( null, null, "ABs", "idA", "idB", "`As`", "id", "Bs", "id" );
}
@Test
public void testNonGeneratedExportedIdentifier(){
testExportedIdentifier( "name1", "name2", "ABs", "idA", "idB", "`As`", "id", "Bs", "id" );
}
private void testExportedIdentifier(
String fkName1,
String fkName2,
String sourceTableName,
String sourceColumnName1,
String sourceColumnName2,
String targetTableName1,
String targetColumnName1,
String targetTableName2,
String targetColumnName2){
TableSpecification targetTable1 = createTable( targetTableName1 );
Column targetColumn1 = targetTable1.createColumn( targetColumnName1 );
TableSpecification targetTable2 = createTable( targetTableName2 );
Column targetColumn2 = targetTable2.createColumn( targetColumnName2 );
TableSpecification sourceTable = createTable( sourceTableName );
Column sourceColumn1 = sourceTable.createColumn( sourceColumnName1 );
Column sourceColumn2 = sourceTable.createColumn( sourceColumnName2 );
ForeignKey fk1 = sourceTable.createForeignKey( targetTable1, fkName1 );
fk1.addColumnMapping( sourceColumn1, targetColumn1 );
ForeignKey fk2 = sourceTable.createForeignKey( targetTable2, fkName2 );
fk2.addColumnMapping( sourceColumn2, targetColumn2 );
Assert.assertTrue( ! fk1.getExportIdentifier().equals( fk2.getExportIdentifier() ) );
}
}