---
title: "hibernate hql(多对多 子查询）"
author: "wanglei0119"
date: "2010-03-03T16:29:22Z"
tags: ["C", "C#", "C++", "Hibernate"]
categories: ["企业架构"]
slug: "hibernate-hql"
draft: false
lastmod: "2010-03-03T16:29:22Z"
id: 607059
url: "https://wanglei0119.iteye.com/blog/607059"
---

现在有两张表，文章(Article) 和 目录(Category).

找出某些个目录中的所有文章的hql:

from Article as a left join a.categories as c where c.id in(:ids)

找出某些目录中但不属于指定目录(id=xxx)的hql:
from Article a where a in (select elements(c.articles) from Category c where c.id in (:ids)) and a not in (select elements(c.articles) from Category c where c.id = xxx)