-
Notifications
You must be signed in to change notification settings - Fork 175
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
base: master
Are you sure you want to change the base?
Fix for issue 2211 #2289
Conversation
Sorry this fix can't be accepted as tests |
1c8cdbf
to
a604ea8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm missing there tests. See mainly JUnitJPQLFunctionsTest.java
or with this
alias generation JUnitJPQLJakartaDataNoAliasTest.java
Hi @rfelcman |
Hi @rfelcman I went through the mail. Is @IdClass is not supported in EclipseLink? |
Of course |
Hi @rfelcman I have send an mail can you please check it out ? |
Hi @rfelcman To handle this scenario, I attempted to add logic to check if the entity is using @IdClass. Below is an example of the extra else if block I added:
However, I’m unsure of the specific logic that needs to go inside the if block to correctly process an entity with @IdClass. |
I think, that MetadataDescriptor.java is too generic. Try Line 605 in 2dd631c
And another area where fix should be targeted is org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.EmbeddedIdAccessor or org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.DerivedIdClassAccessor
|
I'm missing Unit/integration test like |
Hi @rfelcman I have added unit test case . Please check |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After resolve code comments please rebase this PR against latest master and update copyright years in the file headers.
String idAttributeName = getIdAttributeNameByField(descriptor.getMappings(), primaryKeyFields.get(0)); | ||
StateFieldPathExpression stateFieldPathExpression = new StateFieldPathExpression(expression.getParent(), variableText + "." + idAttributeName); | ||
expression.setStateFieldPathExpression(stateFieldPathExpression); | ||
if (!isEmbeddable(descriptor.getMappings())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this part should be refactored into
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(
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);
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another comment: Maybe mentioned code should be optimized to remove some duplicitous calls.
@@ -630,7 +631,7 @@ private void visitAbstractSelectClause(AbstractSelectClause expression) { | |||
multipleSelects = false; | |||
expression.getSelectExpression().accept(this); | |||
|
|||
if (multipleSelects) { | |||
if (multipleSelects || (expression.getSelectExpression() instanceof IdExpression)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(expression.getSelectExpression() instanceof IdExpression)
is not correct pattern in this context. There should be new method with
@Override
public void visit(IdExpression expression) {
multipleSelects = true;
...
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rfelcman What should be the content of this method ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know, check other public void visit(
as examples.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rfelcman Do you mean to check whether the expression is an instance of IdExpression inside visit() method ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rfelcman Do you mean to check whether the expression is an instance of IdExpression inside visit() method ?
Yes. Main reason is eliminate || (expression.getSelectExpression() instanceof IdExpression)
by new public void visit(IdExpression expression) {
method which is called automaticaly by visitor pattern.
.getResultList(); | ||
|
||
// Ensure the result size is greater than 0 | ||
assertTrue("The result size should be greater than 0", !keys.isEmpty()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is not enough. Please add there asserts for a values.
@rfelcman Shall I make the changes and update the PR ? |
Yes this is why PR technology exists plus hooked test calls which will verify modified code. |
I don't see any changes in the code -> no any reason to review it again. |
This PR contains a fix for issue #2211. The query now correctly includes all primary keys instead of just one.