HQL query error

I am a hava java application with two objects: User.java and Review.java.

Each user can have many reviews.

The Review object has a User object (for example: review.getUser ())

I need an hql request that will get all users who do not have Reviews. How to do it?

+3
source share
3 answers
from User u where not exists (from Review r where r.user = u)
+1
source

Try

from User u where u.reviews is empty

Assuming your user class has a collection of reviews, of course ...

+4
source

I do not know your tables and columns in these tables, but in any case you should have a query such as:

select *
from User 
where not exists (select Review where Review.userId = User.id )
0
source

All Articles