From 1097b7733899b8f2907826a3d17cedca76f7d18a Mon Sep 17 00:00:00 2001 From: luiseufrasio Date: Fri, 24 Feb 2023 11:55:11 -0300 Subject: [PATCH] FISH-7076 : Malformed SQL Query caused by EclipseLink with Table per class inheritance and secondary tables --- .../internal/expressions/FieldExpression.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/internal/expressions/FieldExpression.java b/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/internal/expressions/FieldExpression.java index 3a6e70550ae..17af092c0bf 100644 --- a/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/internal/expressions/FieldExpression.java +++ b/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/internal/expressions/FieldExpression.java @@ -273,7 +273,11 @@ public Expression rebuildOn(Expression newBase) { } if ((descriptor != null) && descriptor.hasTablePerClassPolicy()) { field = field.clone(); - field.setTable(descriptor.getDefaultTable()); + DatabaseTable table = descriptor.getDefaultTable(); + if((field.getTableName().length() != 0) && descriptor.getTableNames().contains(field.getTableName())) { + table = descriptor.getTable(field.getTableName()); + } + field.setTable(table); } } FieldExpression expression = new FieldExpression(field, getBaseExpression().rebuildOn(newBase)); @@ -310,7 +314,11 @@ public Expression twistedForBaseAndContext(Expression newBase, Expression contex } if ((descriptor != null) && descriptor.hasTablePerClassPolicy()) { field = field.clone(); - field.setTable(descriptor.getDefaultTable()); + DatabaseTable table = descriptor.getDefaultTable(); + if((field.getTableName().length() != 0) && descriptor.getTableNames().contains(field.getTableName())) { + table = descriptor.getTable(field.getTableName()); + } + field.setTable(table); } } return twistedBase.getField(field);