OrderSpecifier nullsFirst/nullsLast does not follow the JPQL grammar #461

Closed
daniel-frank opened this Issue Jul 25, 2013 · 9 comments

Comments

Projects
None yet
2 participants
@daniel-frank

Using QueryDSL 3.2.1 (Maven Central) this code

c.cbo.descricao.asc().nullsLast()

serializes to

cargo.cbo.descricao is null

Looking at the source of the problem i found this code in JPQLSerializer.java(line 221)

// order by
if (!orderBy.isEmpty() && !forCountRow) {
    append(ORDER_BY);
    boolean first = true;
    for (final OrderSpecifier<?> os : orderBy) {
        if (!first) {
            append(COMMA);
        }
        handle(os.getTarget());
        if (os.getNullHandling() == OrderSpecifier.NullHandling.NullsFirst) {
            append(" is not null, ");
            handle(os.getTarget());
        } else if (os.getNullHandling() == OrderSpecifier.NullHandling.NullsLast) {
            append(" is null, ");
            handle(os.getTarget());
        }
        append(os.getOrder() == Order.ASC ? " asc" : " desc");
        first = false;
    }

Thanks in advance

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Jul 27, 2013

Member

Do you get an Exception? Which JPA provider and database are you using?

Member

timowest commented Jul 27, 2013

Do you get an Exception? Which JPA provider and database are you using?

@daniel-frank

This comment has been minimized.

Show comment
Hide comment
@daniel-frank

daniel-frank Jul 27, 2013

Yup.

//Exception:
java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager: 
Exception Description: Syntax error parsing [select trabalhadorCargo.matricula, trabalhadorCargo.trabalhador.nome, trabalhadorCargo.dataAdmissao, trabalhadorCargo.centroCusto, trabalhadorCargo.cbo, coalesce(an.valor, ?1), coalesce(i.valor, ?1), coalesce(p.valor, ?1), coalesce(s.valor, ?1)
from TrabalhadorCargo trabalhadorCargo
  left join CalculoFormula an on an.trabalhadorCargo = trabalhadorCargo and an.calculoReferencia = ?2 and an.codigo = ?3
  left join CalculoFormula i on i.trabalhadorCargo = trabalhadorCargo and i.calculoReferencia = ?2 and i.codigo = ?4
  left join CalculoFormula p on p.trabalhadorCargo = trabalhadorCargo and p.calculoReferencia = ?2 and p.codigo = ?5
  inner join CalculoFormula s on s.trabalhadorCargo = trabalhadorCargo and s.calculoReferencia = ?2 and s.codigo = ?6
where trabalhadorCargo.empresaMFP = ?7
order by trabalhadorCargo.cbo.descricao is null, trabalhadorCargo.cbo.descricao asc]. 
[797, 835]  The expression is invalid, which means it does not follow the JPQL grammar.

JPA provider: Eclipselink 2.4.2
Database: PostgreSQL 9.1

Yup.

//Exception:
java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager: 
Exception Description: Syntax error parsing [select trabalhadorCargo.matricula, trabalhadorCargo.trabalhador.nome, trabalhadorCargo.dataAdmissao, trabalhadorCargo.centroCusto, trabalhadorCargo.cbo, coalesce(an.valor, ?1), coalesce(i.valor, ?1), coalesce(p.valor, ?1), coalesce(s.valor, ?1)
from TrabalhadorCargo trabalhadorCargo
  left join CalculoFormula an on an.trabalhadorCargo = trabalhadorCargo and an.calculoReferencia = ?2 and an.codigo = ?3
  left join CalculoFormula i on i.trabalhadorCargo = trabalhadorCargo and i.calculoReferencia = ?2 and i.codigo = ?4
  left join CalculoFormula p on p.trabalhadorCargo = trabalhadorCargo and p.calculoReferencia = ?2 and p.codigo = ?5
  inner join CalculoFormula s on s.trabalhadorCargo = trabalhadorCargo and s.calculoReferencia = ?2 and s.codigo = ?6
where trabalhadorCargo.empresaMFP = ?7
order by trabalhadorCargo.cbo.descricao is null, trabalhadorCargo.cbo.descricao asc]. 
[797, 835]  The expression is invalid, which means it does not follow the JPQL grammar.

JPA provider: Eclipselink 2.4.2
Database: PostgreSQL 9.1

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Jul 27, 2013

Member

As both Hibernate and Eclipselink support NULLS FIRST/LAST now, they are now also directly used in Querydsl

Member

timowest commented Jul 27, 2013

As both Hibernate and Eclipselink support NULLS FIRST/LAST now, they are now also directly used in Querydsl

@daniel-frank

This comment has been minimized.

Show comment
Hide comment
@daniel-frank

daniel-frank Jul 27, 2013

Ok, awesome. Any ETA?

Ok, awesome. Any ETA?

timowest added a commit that referenced this issue Jul 28, 2013

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Jul 28, 2013

Member

I will make a new release next week. In the meantime you can use the latest snapshot from here https://oss.sonatype.org/content/repositories/snapshots/

Member

timowest commented Jul 28, 2013

I will make a new release next week. In the meantime you can use the latest snapshot from here https://oss.sonatype.org/content/repositories/snapshots/

@daniel-frank

This comment has been minimized.

Show comment
Hide comment
@daniel-frank

daniel-frank Jul 28, 2013

Appreciated, thank you for the quickly answer. QueryDSL has making a great success where I work here in Brazil.

Appreciated, thank you for the quickly answer. QueryDSL has making a great success where I work here in Brazil.

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Jul 29, 2013

Member

Released in 3.2.2

Member

timowest commented Jul 29, 2013

Released in 3.2.2

@timowest timowest closed this Jul 29, 2013

@timowest timowest added this to the 3.2.2 milestone Apr 14, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment