JPAQuery query = new JPAQuery(em);
private QSalesDeal deal = QSalesDeal.salesDeal;
private QClientUser primarySalesperon = QClientUser.clientUser;
private QClientUser secondarySalesperon = QClientUser.clientUser;
query = query.from(deal);
query.innerJoin(deal.salesPerson1, primarySalesperon);
query.leftJoin(deal.salesPerson2, secondarySalesperon);
List<GrossProfitLeadRecord> leadRecords = query.list(new QGrossProfitLeadRecord(deal.id,
lead.id,
deal.dealNumber,
deal.bookDate,
primarySalesperon.id,
primarySalesperon.firstName,
primarySalesperon.lastName,
secondarySalesperon.firstName,
secondarySalesperon.lastName));
It returns the following sql:
SELECT salesdeal0_.id AS col_0_0_,
salesdeal0_.dealnumber AS col_2_0_,
salesdeal0_.bookdate AS col_3_0_,
clientuser5_.id AS col_7_0_,
clientuser5_.firstname AS col_8_0_,
clientuser5_.lastname AS col_9_0_,
clientuser5_.firstname AS col_10_0_,
FROM buzztrak3.deal salesdeal0_
INNER JOIN buzztrak3.bzuser clientuser3_ ON salesdeal0_.salesperson1id = clientuser3_.id
LEFT OUTER JOIN buzztrak3.bzuser clientuser5_ N salesdeal0_.salesperson2id = clientuser5_.id
You will notice in the select clause that the table references are incorrect and is only referencing the last table added with target. Is this a bug? known limitation or am I just simply missing something.
QClientUser primarySalesperson = new QClientUser("primarySalesperson");
QClientUser secondarySalesperson = new QClientUser("secondarySalesperson");
Timo
query.from(cat)
.innerJoin(cat.mate, mate)
.leftJoin(cat.kittens, kitten)
.list(cat);Awesome that works.Thanks for the quick reply.Can you provide a little more detail on how that differs to what I was doing. Our office has been following the documentation about how to do joinsquery.from(cat) .innerJoin(cat.mate, mate) .leftJoin(cat.kittens, kitten) .list(cat);
Maybe you can add a section to the documentation about this case as I could not easily find anything. Thou I have been known for missing the obvious!