diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/CopyIdentifierComponentSecondPass.java b/hibernate-core/src/main/java/org/hibernate/cfg/CopyIdentifierComponentSecondPass.java index 9e49149ea2..3ad1b83451 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/CopyIdentifierComponentSecondPass.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/CopyIdentifierComponentSecondPass.java @@ -15,6 +15,11 @@ import java.util.concurrent.atomic.AtomicInteger; import org.hibernate.AnnotationException; import org.hibernate.AssertionFailure; import org.hibernate.MappingException; +import org.hibernate.boot.model.naming.Identifier; +import org.hibernate.boot.model.naming.ImplicitNamingStrategy; +import org.hibernate.boot.model.naming.ObjectNameNormalizer; +import org.hibernate.boot.model.naming.PhysicalNamingStrategy; +import org.hibernate.boot.model.relational.Database; import org.hibernate.boot.spi.MetadataBuildingContext; import org.hibernate.mapping.Column; import org.hibernate.mapping.Component; @@ -192,7 +197,12 @@ public class CopyIdentifierComponentSecondPass implements SecondPass { } final String columnName = joinColumn == null || joinColumn.isNameDeferred() ? "tata_" + column.getName() : joinColumn .getName(); - value.addColumn( new Column( columnName ) ); + + final Database database = buildingContext.getMetadataCollector().getDatabase(); + final PhysicalNamingStrategy physicalNamingStrategy = buildingContext.getBuildingOptions().getPhysicalNamingStrategy(); + final Identifier explicitName = database.toIdentifier( columnName ); + final Identifier physicalName = physicalNamingStrategy.toPhysicalColumnName( explicitName, database.getJdbcEnvironment() ); + value.addColumn( new Column( physicalName.render( database.getDialect() ) ) ); if ( joinColumn != null ) { applyComponentColumnSizeValueToJoinColumn( column, joinColumn ); joinColumn.linkWithValue( value ); diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/annotations/TableBinder.java b/hibernate-core/src/main/java/org/hibernate/cfg/annotations/TableBinder.java index 6f5034664e..2e5995f456 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/annotations/TableBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/annotations/TableBinder.java @@ -666,6 +666,7 @@ public class TableBinder { boolean match = false; //for each PK column, find the associated FK column. col = (org.hibernate.mapping.Column) idColItr.next(); + final String colName = col.getQuotedName( buildingContext.getMetadataCollector().getDatabase().getJdbcEnvironment().getDialect() ); for (Ejb3JoinColumn joinCol : columns) { String referencedColumn = joinCol.getReferencedColumn(); referencedColumn = buildingContext.getMetadataCollector().getPhysicalColumnName( @@ -673,7 +674,7 @@ public class TableBinder { referencedColumn ); //In JPA 2 referencedColumnName is case insensitive - if ( referencedColumn.equalsIgnoreCase( col.getQuotedName( buildingContext.getMetadataCollector().getDatabase().getJdbcEnvironment().getDialect() ) ) ) { + if ( referencedColumn.equalsIgnoreCase( colName ) ) { //proper join column if ( joinCol.isNameDeferred() ) { joinCol.linkValueUsingDefaultColumnNaming(