现有实体:Account和Role,Account到Role是多对多的单向关联。
需求:查找拥有某个特定Role的Account,即类似于:from Account a where a.roles contains ? 这样的查询
解决方案:HQL不提供contains的查询,但可以利用join,解决方法是:select a from Account a join a.roles r where r.id = ?
心得:HQL 的join后面不一定非要跟一个实体,不能被SQL的思维定势套牢了!