开发者

HQL Query Based on Set Contents

I have a hibernate managed POJO with a set:

public class Book {
    private Set<Page> pages;
    public Set<Page> getPages() { return pages; }
    public void setPages(Set<Page> pa开发者_开发百科ges) { this.pages = pages; }
}
public class Page {
    private int pageNumber;
    public int getPageNumber() { return pageNumber; }
    public void setPageNumber(int pageNumber) { this.pageNumber = pageNumber;
}

How would I write a HQL query based on the page number? For example, return all books that have a pageNumber greater than 100?

The following does not work:

from Book where pages.pageNumber > 100


Use join:

select distinct b from Book b join b.pages p where p.pageNumber > 100

Without distinct it would return a separate instance of Book for each page satisfying the condition.

See also:

  • 16.3. Associations and joins


using implicit join

from Book b where b.pages.pageNumber > 100

This one is easier

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜