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

DATAJPA-1822 - Ensure left outer join for nested optional attributes #436

Closed

Conversation

pblanchardie
Copy link
Contributor

@pblanchardie pblanchardie commented Nov 19, 2020

Suggested fix for DATAJPA-1822.

It is similar to DATAJPA-1418 (#294).

Reading the git history of toExpressionRecursively shows that multiples attempts have been made to deal with LEFT OUTER JOIN and Path.get depending on several conditions.

The isForSelection parameter, when set to true by toJpaOrder, partly solves the problem.

The new hasRequiredOuterJoin parameter keeps track of previous outer joins to avoid further inner joins on the same path.

toExpressionRecursively has been rewritten to be more readable and create or reuse joins properly.

  • You have read the Spring Data contribution guidelines.
  • There is a ticket in the bug tracker for the project in our JIRA.
  • You use the code formatters provided here and have them applied to your changes. Don’t submit any formatting related changes.
  • You submit test cases (unit or integration tests) that back your changes.
  • You added yourself as author in the headers of the classes you touched. Amend the date range in the Apache license header if needed. For new types, add the license header (copy from another file and set the current year only).

@pivotal-issuemaster
Copy link

@pblanchardie Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

@pivotal-issuemaster
Copy link

@pblanchardie Thank you for signing the Contributor License Agreement!

@pblanchardie pblanchardie changed the title fix DATAJPA-1822 DATAJPA-1822 - fix optional with nested non-optional producing inner join instead of left outer join Nov 19, 2020
@pblanchardie pblanchardie force-pushed the issue/DATAJPA-1822 branch 4 times, most recently from 2deabac to 6146ab4 Compare November 23, 2020 14:49
@pblanchardie pblanchardie changed the title DATAJPA-1822 - fix optional with nested non-optional producing inner join instead of left outer join DATAJPA-1822 - Ensure left outer join for nested optional attributes Nov 23, 2020
@pblanchardie pblanchardie force-pushed the issue/DATAJPA-1822 branch 4 times, most recently from 84f947c to 3017539 Compare December 30, 2020 14:14
@pblanchardie
Copy link
Contributor Author

Hi @schauder, I would appreciate some feedback and don't hesitate to ask for clarification.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jan 4, 2021
@mp911de mp911de assigned pblanchardie and schauder and unassigned pblanchardie Feb 15, 2021
@schauder schauder self-requested a review February 26, 2021 08:01
@schauder schauder removed the status: waiting-for-triage An issue we've not yet triaged label Feb 26, 2021
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Feb 26, 2021
Copy link
Contributor

@schauder schauder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two integration tests fail with EclipseLink:

Please make sure to run all tests with ./mvnw clean verify

[ERROR] Failures: 
[ERROR]   EclipseLinkQueryUtilsIntegrationTests>QueryUtilsIntegrationTests.createsLeftJoinForNonOptionalToOneWithNestedOptional:147 
Expecting empty but was: [org.eclipse.persistence.internal.jpa.querydef.JoinImpl@56bb4183]
[ERROR]   EclipseLinkQueryUtilsIntegrationTests>QueryUtilsIntegrationTests.createsLeftJoinForOptionalToOneWithNestedNonOptional:131 
Expecting empty but was: [org.eclipse.persistence.internal.jpa.querydef.JoinImpl@7b1248b8]

@pblanchardie pblanchardie force-pushed the issue/DATAJPA-1822 branch 3 times, most recently from 27e7c21 to 4bc11ac Compare February 26, 2021 17:51
@pblanchardie
Copy link
Contributor Author

pblanchardie commented Feb 26, 2021

Two integration tests fail with EclipseLink:

Temporarily fixed by skipping these tests for EclipseLink.

This is caused by QueryUtils.java#L699 producing an inner join.
Looks like EclipseLink Bug 413892, but also occurs with EclipseLink 2.7.5.

The existing workaround using ManagedType does not work for intermediate levels (when from is a Join).

@pblanchardie
Copy link
Contributor Author

Added a workaround for EclipseLink (inspired by the existing workaround using ManagedType) that also handles intermediate joins.
Updated the comment from 2013 saying that the workaround is needed for EclipseLink 2.4.x to "still occurs as of 2.7".
Should we add a TODO to plan the removal of these ugly workarounds?
Should we reopen a bug in EclipseLink?

@schauder schauder removed the status: waiting-for-triage An issue we've not yet triaged label Mar 1, 2021
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 1, 2021
@schauder schauder removed the status: waiting-for-triage An issue we've not yet triaged label Mar 2, 2021
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 2, 2021
@schauder schauder removed the status: waiting-for-triage An issue we've not yet triaged label Mar 2, 2021
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 2, 2021
schauder pushed a commit that referenced this pull request Mar 2, 2021
schauder added a commit that referenced this pull request Mar 2, 2021
Formatting.
Preferring iterative code of streams.
Adding `@author` tags for previous changes.

Original pull request: #436
schauder pushed a commit that referenced this pull request Mar 2, 2021
schauder added a commit that referenced this pull request Mar 2, 2021
Formatting.
Preferring iterative code of streams.
Adding `@author` tags for previous changes.

Original pull request: #436
schauder pushed a commit that referenced this pull request Mar 2, 2021
schauder added a commit that referenced this pull request Mar 2, 2021
Formatting.
Preferring iterative code of streams.
Adding `@author` tags for previous changes.

Original pull request: #436
@schauder
Copy link
Contributor

schauder commented Mar 2, 2021

Should we reopen a bug in EclipseLink?

Thanks for bringing this to the attention of the EclipseLink team.
But it seems this is more of a Spec question now:
jakartaee/persistence#169

@schauder
Copy link
Contributor

schauder commented Mar 2, 2021

Thanks, this is merged, polished and back ported.

@schauder schauder closed this Mar 2, 2021
@schauder schauder added this to the 2.3.8 (Neumann SR8) milestone Mar 2, 2021
@schauder schauder removed the status: waiting-for-triage An issue we've not yet triaged label Mar 2, 2021
schauder pushed a commit that referenced this pull request Mar 2, 2021
schauder added a commit that referenced this pull request Mar 2, 2021
Formatting.
Preferring iterative code of streams.
Adding `@author` tags for previous changes.

Original pull request: #436
schauder pushed a commit that referenced this pull request Mar 2, 2021
schauder added a commit that referenced this pull request Mar 2, 2021
Formatting.
Preferring iterative code of streams.
Adding `@author` tags for previous changes.

Original pull request: #436
schauder pushed a commit that referenced this pull request Mar 2, 2021
schauder added a commit that referenced this pull request Mar 2, 2021
Formatting.
Preferring iterative code of streams.
Adding `@author` tags for previous changes.

Original pull request: #436
schauder added a commit that referenced this pull request Mar 3, 2021
Made test methods public for JUnit 4.

Original pull request: #436
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sorting on nested optional relations produces inner joins instead of outer joins [DATAJPA-1822]
4 participants