开发者

Hibernate criteria restriction on a property for all elements of a set

I have an entity with a set say like

Library---><Set>books

Now I want to retrieve the libraries where ALL the 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 query I get 开发者_运维知识库the libraries where at least one book has a genre but I'd like hibernate to check the genre property for all the elements of the book set and return the libraries where ALL the elements satisfy the not null restriction.

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

Thanks.


May be 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...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜