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

Joins are not generated if ordering of associated property determined by a function #698

Closed
thomasdarimont opened this issue Apr 7, 2014 · 5 comments
Labels
bug
Milestone

Comments

@thomasdarimont
Copy link

@thomasdarimont thomasdarimont commented Apr 7, 2014

Hello,

it seems that querydsl doesn't generate the necessary (left) joins when ordering by a property of an associated entity for which the value to order by is determined by a function -> e.g. .orderBy(person.address.city.lower().asc());

Is this a bug in querydsl or do we generate the order specifies incorrectly?

We construct an appropriate PathBuilder here:
https://github.com/spring-projects/spring-data-jpa/blob/master/src/main/java/org/springframework/data/jpa/repository/support/Querydsl.java#L189
and add the newly created orderBy expression to the JPAQuery here:
https://github.com/spring-projects/spring-data-jpa/blob/master/src/main/java/org/springframework/data/jpa/repository/support/Querydsl.java#L164

Did we miss something?

QPerson person = QPerson.person;

JPAQuery qry = new JPAQuery(em, HQLTemplates.DEFAULT) //
        .from(person) //
        .where(person.id.lt(3)) //
        .orderBy(person.address.city.asc()); //

Generates:

select person
from Person person
  left join person.address as person_address
where person.id < ?1
order by person_address.city asc

However:

QPerson person = QPerson.person;

JPAQuery qry = new JPAQuery(em, HQLTemplates.DEFAULT) //
        .from(person) //
        .where(person.id.lt(3)) //
        .orderBy(person.address.city.lower().asc()); //

Generates:

select person
from Person person
where person.id < ?1
order by lower(person.address.city) asc

Cheers,
Thomas

@timowest
Copy link
Member

@timowest timowest commented Apr 7, 2014

It's a bug, or inconsistent behaviour. I will look into it.

@timowest
Copy link
Member

@timowest timowest commented Apr 7, 2014

@thomasdarimont Could you take a look at this #701

I made a SNAPSHOT for this branch available with the 3.3.3.i698-SNAPSHOT version in https://oss.sonatype.org/content/repositories/snapshots/

@thomasdarimont
Copy link
Author

@thomasdarimont thomasdarimont commented Apr 7, 2014

Hello Timo,

The following query definition

JPAQuery qry = new JPAQuery(em, HQLTemplates.DEFAULT) //
                .from(person) //
                .where(person.id.lt(3)) //
                .orderBy(person.address.city.lower().asc()); //

Now produces the correct sql:

select person
from Person person
  left join person.address as person_address
where person.id < ?1
order by lower(person_address.city) asc

It seems to work now - I'll do more intensive testing tomorrow!
Thanks for the update!

Cheers,
Thomas

@thomasdarimont
Copy link
Author

@thomasdarimont thomasdarimont commented Apr 8, 2014

Quick update:

I checked the snapshot against the current Spring Data JPA master branch - everything works as expected.

Looks good to me :)

Cheers,
Thomas

@timowest timowest closed this in #701 Apr 8, 2014
@timowest timowest added the fixed label Apr 8, 2014
@timowest timowest reopened this Apr 8, 2014
@timowest timowest modified the milestone: 3.3.3 Apr 13, 2014
@timowest timowest modified the milestone: 3.3.3 Apr 30, 2014
@timowest
Copy link
Member

@timowest timowest commented May 2, 2014

Released in 3.3.3

@timowest timowest closed this May 2, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

2 participants
You can’t perform that action at this time.