对集合中所有元素的属性的Hibernate条件限制 [英] Hibernate criteria restriction on a property for all elements of a set

查看:128
本文介绍了对集合中所有元素的属性的Hibernate条件限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个有集合的实体,像

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.

所以我有这样的东西:

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

如果我执行查询,我会得到至少有一本书有类型
的库但我希望hibernate检查书集的所有元素的流派属性,并返回所有元素满足非空限制的库。

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.

谢谢。

推荐答案

可能类似于:

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

这篇关于对集合中所有元素的属性的Hibernate条件限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆