Reputation: 923
I have many2one relation between 2 entities Question
and Answer
with many2one defined in Answer' and no one2many defined in
Question`.
How can i query with hibernate the questions that do not have any answers without adding one2many relation in Question
entity?
something like:
select distinct q from Question q
left join Answer a on a.question_id=q.id
where a.id is null
Upvotes: 0
Views: 647
Reputation: 12180
Something like this:
select q from Question q
where q not in (select a.question from Answer a)
Btw, your supplied query is "too much SQL", remember that although their syntax are similar, SQL and JPQL are conceptually different.
Upvotes: 1