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

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

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

Comments

@daniel-frank
Copy link

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
Copy link
Member

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

@daniel-frank
Copy link
Author

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
Copy link
Member

It appears EclipseLink supports nulls first/last directly http://java-persistence-performance.blogspot.fi/2012/05/jpql-vs-sql-have-both-with-eclipselink.html

@daniel-frank
Copy link
Author

@timowest
Copy link
Member

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

@daniel-frank
Copy link
Author

Ok, awesome. Any ETA?

timowest added a commit that referenced this issue Jul 28, 2013
@timowest
Copy link
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/

@daniel-frank
Copy link
Author

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

@timowest
Copy link
Member

Released in 3.2.2

@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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants