Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specify alias on join clause using QueryDSL

Tags:

java

sql

querydsl

Using QueryDSL I would create a query like the following:

select * from cats as C join owners as O on ...

For readability reasons I would apply the alias "O" in the join clause, but the DSL doesn't seem to support this:

query.from(cats.as("C")).join(owners.as("O")).on(...)

The type of owners.as("O") isn't compatible with types expected by join clause.

Have you any idea?

like image 706
maurocchi Avatar asked Feb 05 '15 12:02

maurocchi


2 Answers

Ok, instead of using the autogenerated static instance of a table, you can simply create it with an alias:

Cat cat = new Cat("C");
Owner owner = new Owner("O");
query.from(cats).join(owners).on(...)
like image 130
maurocchi Avatar answered Nov 19 '22 03:11

maurocchi


You can use Alias in Querydsl like

QCat cat = new QCat("C");

Querydsl Alias usage

like image 32
Philip YW Avatar answered Nov 19 '22 03:11

Philip YW