Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for issue 2211 #2289

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,26 @@ public void visit(IdExpression expression) {
//Get id attribute name
ClassDescriptor descriptor = this.queryContext.getDeclaration(variableName).getDescriptor();
List<DatabaseField> primaryKeyFields = descriptor.getPrimaryKeyFields();
String idAttributeName = getIdAttributeNameByField(descriptor.getMappings(), primaryKeyFields.get(0));
StateFieldPathExpression stateFieldPathExpression = new StateFieldPathExpression(expression.getParent(), variableText + "." + idAttributeName);
expression.setStateFieldPathExpression(stateFieldPathExpression);
if (!isEmbeddable(descriptor.getMappings())) {
for (DatabaseField primaryKeyField : primaryKeyFields) {
String idAttributeName = getIdAttributeNameByField(descriptor.getMappings(), primaryKeyField);
StateFieldPathExpression stateFieldPathExpression = new StateFieldPathExpression(
expression.getParent(), variableText + "." + idAttributeName);
expression.setStateFieldPathExpression(stateFieldPathExpression);
// Continue with created StateFieldPathExpression
// It handle by ObjectBuilder booth @Id/primary key types (simple/composite)
expression.getStateFieldPathExpression().accept(this);
}
} else {
String idAttributeName = getIdAttributeNameByField(descriptor.getMappings(), primaryKeyFields.get(0));
StateFieldPathExpression stateFieldPathExpression = new StateFieldPathExpression(
expression.getParent(), variableText + "." + idAttributeName);
expression.setStateFieldPathExpression(stateFieldPathExpression);
// Continue with created StateFieldPathExpression
// It handle by ObjectBuilder booth @Id/primary key types (simple/composite)
expression.getStateFieldPathExpression().accept(this);

//Continue with created StateFieldPathExpression
//It handle by ObjectBuilder booth @Id/primary key types (simple/composite)
expression.getStateFieldPathExpression().accept(this);
}
}

/**
Expand All @@ -96,10 +109,24 @@ public void visit(VersionExpression expression) {

private String getIdAttributeNameByField(List<DatabaseMapping> databaseMappings, DatabaseField field) {
for (DatabaseMapping mapping : databaseMappings) {
if (field.equals(mapping.getField()) || mapping.isPrimaryKeyMapping()) {
if (mapping.getFields().size() > 1 && (field.equals(mapping.getField()) || mapping.isPrimaryKeyMapping())) {
return mapping.getAttributeName();
} else {
if ((field.equals(mapping.getField()) && mapping.isPrimaryKeyMapping())) {
return mapping.getAttributeName();
}
}
}
return null;
}

private boolean isEmbeddable(List<DatabaseMapping> databaseMappings) {

for (DatabaseMapping databaseMapping : databaseMappings) {
if (databaseMapping.isPrimaryKeyMapping() && databaseMapping.getFields().size() > 1) {
return true;
}
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.eclipse.persistence.jpa.jpql.parser.EntryExpression;
import org.eclipse.persistence.jpa.jpql.parser.ExtractExpression;
import org.eclipse.persistence.jpa.jpql.parser.FunctionExpression;
import org.eclipse.persistence.jpa.jpql.parser.IdExpression;
import org.eclipse.persistence.jpa.jpql.parser.IdentificationVariable;
import org.eclipse.persistence.jpa.jpql.parser.IndexExpression;
import org.eclipse.persistence.jpa.jpql.parser.Join;
Expand Down Expand Up @@ -630,7 +631,7 @@ private void visitAbstractSelectClause(AbstractSelectClause expression) {
multipleSelects = false;
expression.getSelectExpression().accept(this);

if (multipleSelects) {
if (multipleSelects || (expression.getSelectExpression() instanceof IdExpression)) {
query.returnWithoutReportQueryResult();
}
else {
Expand Down
Loading