querydsl / querydsl

Unified Queries for Java
https://querydsl.com
Apache License 2.0
4.75k stars 873 forks source link

SQL aliasing contains tablename when path is used #1572

Closed TuomasKiviaho closed 9 years ago

TuomasKiviaho commented 9 years ago

I've used to do aliasing by reusing the original path SFoo.bar.nullif(0).as(SFoo.bar). This nowadays leads to NULLIF("foo"."bar", 0 ) AS "foo"."bar" but it used to be NULLIF("foo"."bar", 0 ) AS "bar".

The new form doesn't work with neither H2 or MySQL and I guess that other databases do not appreciate it either.

As a workaround I used SFoo.bar.nullif(0).as(SFoo.bar.getMetadata().getName()) which turns the path into a variable and hence works as expected.

I guess this has been done to support aliasing in some other parts of the query (JOIN maybe), but it doesn't work as SELECT anymore. I see that SQLSerializer has gimmicks involving Ops.ALIAS so could it be possible to intervene there how the result is actually printed out

timowest commented 9 years ago

Does this happen with Querydsl SQL or JPA native queries or both?

TuomasKiviaho commented 9 years ago

I've only tested this against QueryDSL SQL via SimpleExpression

timowest commented 9 years ago

The same error seems to be present in Querydsl 3. Which version did you use?

TuomasKiviaho commented 9 years ago

QueryDSL 3.6.7. The project I encountered this with has been dormant for quite some while so this is not something that has been introduced recently. I see that with 3.6.3 it was still working.

UPDATE: Just to be absolutely sure I run our integration test against 3.6.3 without the workaround and it worked.