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

Joining a path multiple times #3

Closed
beikov opened this issue Jul 21, 2014 · 1 comment
Closed

Joining a path multiple times #3

beikov opened this issue Jul 21, 2014 · 1 comment
Assignees
Milestone

Comments

@beikov
Copy link
Member

beikov commented Jul 21, 2014

Currently we can only join a path like "doc.localized.name" once, but it is sometimes necessary to join it multiple times with different aliases.

This is especially necessary for queries that use indexed collections.

If for example one would want to select two distinct values from a map attribute with different keys, the resulting JPQL Query could look like:

"SELECT o1, o2, FROM SomeType s LEFT JOIN s.map o1 LEFT JOIN s.map o2 WHERE KEY(o1) = 1 AND KEY(o2) = 2"

Note that this query in contrast to the next one, only returns a result, if both there are objects for both keys 1 and 2.

"SELECT o1, o2, FROM SomeType s LEFT JOIN s.map o1 LEFT JOIN s.map o2 WHERE KEY(o1) = 1 OR KEY(o2) = 2"

This query would return null for o2 if there was no entry with key 2.

When enabling this feature, please consider the different use cases.

@Mobe91
Copy link
Contributor

Mobe91 commented Jul 22, 2014

Referring to InterfaceViewTest.testInterface(), following query is generated so far:

SELECT contacts, d.id, contacts, d.name FROM Document d LEFT JOIN d.contacts contacts WHERE KEY(contacts) = 1 AND KEY(contacts) = :contactPersonNumber ORDER BY d.id ASC NULLS LAST

This results in an empty result set if :contactPersonNumber != 1
Instead the query should be built like this:

SELECT contacts1, d.id, contacts2, d.name FROM Document d LEFT JOIN d.contacts contacts1 LEFT JOIN d.contacts contacts2 WHERE KEY(contacts1) = 1 OR KEY(contacts2) = :contactPersonNumber ORDER BY d.id ASC NULLS LAST

@beikov beikov modified the milestones: 1.0, 1.1, 1.1.0, 1.0.0 Aug 11, 2014
@beikov beikov closed this as completed in 9a78a56 Aug 20, 2014
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

No branches or pull requests

2 participants