Skip to content

DATAJPA-1418 Interface-based Projections - Generate inner join instead of left join #294

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

Closed
wants to merge 1 commit into from

Conversation

reda-alaoui
Copy link
Contributor

@reda-alaoui reda-alaoui commented Oct 2, 2018

If the PR is accepted, I think a merge to 2.0.x is needed.

By default, when a foreign entity, without further sub attribute, is involved, Hibernate generates an inner join on the table of the foreign entity. Hibernate internals do this before processing the EntityGraph. So even when the final SQL query only fetch the foreign entity ID hold by the primary table, it joins on the foreign table. I don't think Hibernate is going to change this behaviour before 6.0.

The current bug was introduced by DATAJPA-1238 fix. The goal of DATAJPA-1238 was to avoid a useless left outer join when a foreign entity was involved in the query predicate (findByX where X is an entity). Its fix removed the outer join when the navigated foreign entity was a leaf, regardless of the location of the property representing the entity.

My pull request creates a distinction between properties navigated inside the select clause and other properties (i.e. navigated in the predicate). If the entity property is a leaf outside a select clause, DATAJPA-1238 fix is kept, no outer join is generated. If the property is a leaf inside a select clause, an outer join is created as it was before DATAJPA-1238 fix.

schauder pushed a commit that referenced this pull request Oct 17, 2018
…ead of left join.

When a projection contains a reference to an entity we generate an outer join again.
This is necessary since Hibernate insist on creating an inner join instead, which will filter out null values of the reference.

See also: https://hibernate.atlassian.net/browse/HHH-12999.
See also: jakartaee/persistence#189.

Original pull request: #294.
schauder added a commit that referenced this pull request Oct 17, 2018
Added comment with issue id on the test.
Added a comment with a link to the Hibernate issue.

Original pull request: #294.
schauder pushed a commit that referenced this pull request Oct 17, 2018
…ead of left join.

When a projection contains a reference to an entity we generate an outer join again.
This is necessary since Hibernate insist on creating an inner join instead, which will filter out null values of the reference.

See also: https://hibernate.atlassian.net/browse/HHH-12999.
See also: jakartaee/persistence#189.

Original pull request: #294.
schauder added a commit that referenced this pull request Oct 17, 2018
Added comment with issue id on the test.
Added a comment with a link to the Hibernate issue.

Original pull request: #294.
schauder pushed a commit that referenced this pull request Oct 17, 2018
…ead of left join.

When a projection contains a reference to an entity we generate an outer join again.
This is necessary since Hibernate insist on creating an inner join instead, which will filter out null values of the reference.

See also: https://hibernate.atlassian.net/browse/HHH-12999.
See also: jakartaee/persistence#189.

Original pull request: #294.
schauder added a commit that referenced this pull request Oct 17, 2018
Added comment with issue id on the test.
Added a comment with a link to the Hibernate issue.

Original pull request: #294.
@schauder
Copy link
Contributor

Thanks, that is merged.

@schauder schauder closed this Oct 17, 2018
@reda-alaoui
Copy link
Contributor Author

Thanks :)

@reda-alaoui reda-alaoui deleted the DATAJPA-1418 branch October 17, 2018 10:32
stsypanov pushed a commit to stsypanov/spring-data-jpa that referenced this pull request Dec 13, 2019
…ead of left join.

When a projection contains a reference to an entity we generate an outer join again.
This is necessary since Hibernate insist on creating an inner join instead, which will filter out null values of the reference.

See also: https://hibernate.atlassian.net/browse/HHH-12999.
See also: jakartaee/persistence#189.

Original pull request: spring-projects#294.
stsypanov pushed a commit to stsypanov/spring-data-jpa that referenced this pull request Dec 13, 2019
Added comment with issue id on the test.
Added a comment with a link to the Hibernate issue.

Original pull request: spring-projects#294.
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.

2 participants