HHH-14343 Fix quoting of column names when globally quoted identifiers is active

This commit is contained in:
Christian Beikov 2020-11-23 13:46:30 +01:00 committed by Sanne Grinovero
parent 3434293a7e
commit 8ded205b5f
2 changed files with 13 additions and 2 deletions

View File

@ -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 );

View File

@ -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(