Skip to content

Commit

Permalink
Review comments updated
Browse files Browse the repository at this point in the history
  • Loading branch information
ajaypaul-ibm committed Mar 4, 2025
1 parent 8e4a6d4 commit 5141e5c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,15 @@ public void visit(IdExpression expression) {
//Get id attribute name
ClassDescriptor descriptor = this.queryContext.getDeclaration(variableName).getDescriptor();
List<DatabaseField> primaryKeyFields = descriptor.getPrimaryKeyFields();
if (!isEmbeddable(descriptor.getMappings())) {
if (isEmbeddable(descriptor.getMappings())) {
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);
} else {
for (DatabaseField primaryKeyField : primaryKeyFields) {
String idAttributeName = getIdAttributeNameByField(descriptor.getMappings(), primaryKeyField);
StateFieldPathExpression stateFieldPathExpression = new StateFieldPathExpression(
Expand All @@ -73,15 +81,6 @@ public void visit(IdExpression expression) {
// 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);

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -626,12 +626,16 @@ public void visit(ValueExpression expression) {
addAttribute(identificationVariable.getText(), queryExpression);
}

@Override
public void visit(IdExpression expression){
multipleSelects = true;
}
private void visitAbstractSelectClause(AbstractSelectClause expression) {

multipleSelects = false;
expression.getSelectExpression().accept(this);

if (multipleSelects || (expression.getSelectExpression() instanceof IdExpression)) {
if (multipleSelects) {
query.returnWithoutReportQueryResult();
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ public void testCompositePrimaryKey() {

// Ensure the result size is greater than 0
assertTrue("The result size should be greater than 0", !keys.isEmpty());

Assert.assertEquals("first name should be John", "John", keys.get(0).firstName);
Assert.assertEquals("last name should be John", "Doe", keys.get(0).lastName);
} catch (Exception e) {
// If there's an exception, rollback the transaction
rollbackTransaction(em);
Expand Down

0 comments on commit 5141e5c

Please sign in to comment.