Limiting hibernation criteria for a property for all elements of a set

I have an entity with a set, for example

Library---><Set>books 

Now I want to get libraries in which ALL books have a genre.

So, I have something like this:

 c.createCriteria("library", "library").createCriteria("books", "book"); c.add(Restrictions.isNotNull("book.genre")); 

If I execute the request, I get libraries in which at least one book has a genre but I would like hibernate to check the genre property for all elements of the book set and return libraries where ALL elements satisfy a non-empty constraint.

Sorry for my English, I hope the problem is clear, any help is much appreciated.

Thanks.

0
hibernate criteria
source share
1 answer

Maybe something like:

 FROM Library library WHERE not exists (SELECTbook from Book book where book.description=null and book.id in (library.books)) ? 

Just an idea ...

+1
source share

All Articles