I've following classes with FK relation:
Q (1:n) S
Q (1:n) A ( n:1 ) S The relation Q-A is optional (and A-S as well).
Think about Questions with predefined Select options (as answers) and a large number of given Answers.
Now I want to have all Q,S,A with Q,S,null when there is no Q-A relation.
In native SQL this is rather straight forward (fragment):
Code:
from Q inner join S on Q.id = S.q_id
left join A on Q.id = A.q_id and A.s_id = S.id
But how to express this in HQL? I got this far:
Code:
from Q q join q.setS s left join q.setA
with Q.setS the OneToMany mapping of Q to S.
But how to bring in the relation between A and S? (I know that in this case a solution via Q-in-S-oj-A exists, but this is a simplification of a complexer problem I have).
An other slightly different pattern is that the relation between A (n:1) S is not a FK relation but an expression. How to take care of that in HQL?
Thanks,
Erik