That's make my day a pain.
I'm a beginner with HQL and was making a translation between a SQL sentence to HQL.
The SQL sentence is not so complex, It's something like this.
SELECT t.teamworkerdid, COUNT(t.teamworkerdid), SUM(NVL(p.percentagework, 1))
FROM WORKER_TEAM t
LEFT JOIN PARTIAL_WORK p
ON (t.teamworkerdid = p.idworkerteam)
WHERE
( e.startwork <= CURRENT_DATE
AND
e.finishwork >= CURRENT_DATE);
The table WORKER_TEAM has all the workers Id which is the foreign key in the PARTIAL_WORK table. But not all the team workers which are in W_T are in the P_T table, cause workers that are 100% working doesn't have an entry in partial work table. That's the reason y use a Left join and NVL with 1 option.
I made all the transformation between Database table names and POJO's variables. Trying with reduced version of the upper sentence the things go fine, something like SELECT COUNT(t.teamworkerdid) FROM WORKER_TEAM t, PARTIAL_WORK p WHERE (t.teamworkerdid = p.idworkerteam) but in HQL ( I don't change the var names because would confuse everyone).
Ok, natural join works fine*emphasized text*, cause i activate the HQL depuration output in console and obtain the SQL sentence which works fine.
The problem comes when I try to do the LEFT JOIN in HQL, only changing the implicit natural join with a LEFT JOIN, using the WITH keyword instead the ON SQL keyword, the program cracks and throw an Exception. HQL have any problem generating NULL cells are what I'm doing wrong.
Thanks in advance.
P.D. I know NVL doesn't work in HQL, the substitute is *coalesce(column_name, 'asdf')*.