我有这样的课
public User{
Long id;
Set<String> roles;
}
如何查询角色为 "ADMIN"
的所有 User
对象
编辑:
我正在使用 Hibernate 3.0.5。并尝试了大多数显而易见的方法。
来自 Users where roles in('ADMIN')
给出了 JDBC 错误。
来自 Users u where u.roles in('ADMIN')
给出类转换异常
我认为这可能是这个特定版本的 hibernate 的问题。
最佳答案
我找到了解决方案:
"from User as user where 'ADMIN' in elements(user.roles)";
hql 函数 value() 必须以某种方式帮助解决这个问题,您也可以尝试使用它,但上面的 hql 查询对我有用。
关于java - HQL如何查询String的ElementCollection,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14090364/