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

Closed
thomasdarimont opened this Issue Apr 7, 2014 · 5 comments

Comments

Projects
None yet
2 participants
@thomasdarimont

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

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Apr 7, 2014

Member

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

Member

timowest commented Apr 7, 2014

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

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Apr 7, 2014

Member

@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/

Member

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

This comment has been minimized.

Show comment
Hide comment
@thomasdarimont

thomasdarimont 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

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

This comment has been minimized.

Show comment
Hide comment
@thomasdarimont

thomasdarimont 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

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

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest May 2, 2014

Member

Released in 3.3.3

Member

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