I'm getting ERROR: missing FROM-clause entry for table "t3"
when trying to use the following JPQL:
SELECT primeira FROM PrimeiraClasse primeira
LEFT JOIN primeira.segunda.terceira.quarta quarta ON (quarta.quinta = primeira.quinta)
ORDER BY quarta.ordem
The quarta
attribute in the terceira
class is a list, so I need to relate it to the quinta
class attribute that needs to be the same, both in the primeira
class and the quarta
class. Home
However, it is possible that there is no correspondent, so I need LEFT JOIN
.
So the query that was supposed to be mounted would be something like:
SELECT t1.*
FROM primeiratabela t1
JOIN segundatabela t2 ON (t2.id = t1.idsegunda)
JOIN terceiratabela t3 ON (t3.id = t2.idterceira)
JOIN quintatabela t5 ON (t5.id = t1.idquinta)
LEFT JOIN quartatabela t4 ON (t4.idquinta = t5.id AND t4.idterceira = t3.id)
ORDER BY t4.ordem
But in practice the FROM
clause is being reordered, causing the error.
SELECT t1.id AS a1, t1.algo AS a2, t1.idsegunda AS a3, t1.idquinta AS a4
FROM primeiratabela t1 LEFT OUTER JOIN quartatabela t4 ON ((t4.idterceira = t3.id) AND (t4.idquinta = t5.id)), terceiratabela t3, segundatabela t2, quintatabela t5
WHERE (((t1.idsegunda = ?) AND (t1.algo = ?)) AND (((t5.id = t1.idquinta) AND (t2.id = t1.idsegunda)) AND (t3.id = t2.idterceira))) ORDER BY t4.ordem ASC
As the order of junctions is changed improperly, the error occurs.
The question: Is there a way to make sure that joins are done in the way JPQL was written, keeping% s of% s instead of replacing them with join criteria in the INNER JOIN
clause?
Note: When I remove the WHERE
, the query is mounted without LEFT
s, only with criteria in JOIN
, and the error does not occur.
JPA: 2.0; Eclipselink: 2.4.2;