Skip to content

Commit

Permalink
Fix problem with DB2, PostgerSQL with CTE table names for quoted tables
Browse files Browse the repository at this point in the history
  • Loading branch information
dreab8 committed Aug 24, 2021
1 parent 3f87ed1 commit 39ee023
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
Expand Up @@ -15,6 +15,7 @@

import org.hibernate.LockMode;
import org.hibernate.LockOptions;
import org.hibernate.boot.model.naming.Identifier;
import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.metamodel.mapping.EntityMappingType;
Expand Down Expand Up @@ -298,4 +299,16 @@ protected TableReference resolveUnionTableReference(
return tableGroup.getTableReference( tableGroup.getNavigablePath(), tableExpression );
}
}

protected String getCteTableName(String tableExpression) {
if ( Identifier.isQuoted( tableExpression ) ) {
tableExpression = unquote( tableExpression );
return DML_RESULT_TABLE_NAME_PREFIX + tableExpression;
}
return DML_RESULT_TABLE_NAME_PREFIX + tableExpression;
}

private String unquote(String tableExpression) {
return tableExpression.substring( 1, tableExpression.length() - 1 );
}
}
Expand Up @@ -68,7 +68,7 @@ protected void addDmlCtes(
// collection table
final String tableExpression = pluralAttribute.getSeparateCollectionTable();
final CteTable dmlResultCte = new CteTable(
DML_RESULT_TABLE_NAME_PREFIX + tableExpression,
getCteTableName( tableExpression ),
idSelectCte.getCteTable().getCteColumns(),
factory
);
Expand Down Expand Up @@ -97,7 +97,7 @@ protected void addDmlCtes(
getEntityDescriptor().visitConstraintOrderedTables(
(tableExpression, tableColumnsVisitationSupplier) -> {
final CteTable dmlResultCte = new CteTable(
DML_RESULT_TABLE_NAME_PREFIX + tableExpression,
getCteTableName( tableExpression ),
idSelectCte.getCteTable().getCteColumns(),
factory
);
Expand Down
Expand Up @@ -140,7 +140,7 @@ protected void addDmlCtes(
getEntityDescriptor().visitConstraintOrderedTables(
(tableExpression, tableColumnsVisitationSupplier) -> {
final CteTable dmlResultCte = new CteTable(
DML_RESULT_TABLE_NAME_PREFIX + tableExpression,
getCteTableName( tableExpression ),
idSelectCte.getCteTable().getCteColumns(),
factory
);
Expand Down

0 comments on commit 39ee023

Please sign in to comment.