0

I have many2one relation between 2 entities Question and Answer with many2one defined in Answer' and no one2many defined inQuestion`.

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
alizelzele
  • 892
  • 2
  • 19
  • 34

1 Answers1

1

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.

Tobb
  • 11,850
  • 6
  • 52
  • 77
  • Thank you, that worked great. I did not know how to write the hql, so i wrote semi SQL this way for somebody like myself who usually don't read the description and skip to code :P – alizelzele Jan 18 '16 at 08:47