HQL how to query ElementCollection of String

后端 未结 3 1310
长情又很酷
长情又很酷 2021-01-01 00:02

I have class like

public User{
   Long id;
   Set roles;
}

How do I query all User objects with the role of

相关标签:
3条回答
  • 2021-01-01 00:37

    This should do it:

    session.createQuery("from User where roles in ('ADMIN')");
    
    0 讨论(0)
  • 2021-01-01 00:45

    You can use the query below

    "from User as user where user.id in (select user.id from Role as role left join role.user as user where role.name = 'ADMIN')"
    
    0 讨论(0)
  • 2021-01-01 00:58

    I've found solution:

    "from User as user where 'ADMIN' in elements(user.roles)";
    

    Somehow hql function value() have to help with this, you can also experiment with it, but that hql query above works for me.

    0 讨论(0)
提交回复
热议问题