HQL (Hibernate) how to check if a list of elements is a subset of another list?

偶尔善良 提交于 2019-12-05 16:58:37

Maybe something simpler exists, but I've not found it:

select r from Role r where not exists (
    select p.id from Permission p 
    where p.name = 'test'
    and p.id not in (select p2.id from Role r2 inner join r2.permissions p2
                     where r2 = r))

To make it clearer, this query checks that there is no permission of name 'test' that is not in the role permissions, which is the same as saying that all permissions with name 'test' are in the role permissions.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!