HQL如何查询String的ElementCollection [英] HQL how to query ElementCollection of String

查看:94
本文介绍了HQL如何查询String的ElementCollection的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有类像

  public User {
Long id;
Set< String>角色;

$ / code>

如何查询所有用户具有角色ADMIN的对象



编辑: p>

我正在使用Hibernate 3.0.5。并尝试了大多数明显的方法。



来自用户,其中('ADMIN')中的角色给出JDBC错误。 ('ADMIN')中的u.roles给出了类别转换异常




我认为这可能是这个特定版本的hibernate的问题。

解决方案

您可以使用下面的查询

$ (从user.id中选择user.id作为角色作为角色左连接role.user作为用户,其中role.name = 'ADMIN')


I have class like

public User{
   Long id;
   Set<String> roles;
}

How do I query all User objects with the role of "ADMIN"

EDIT:

I'm using Hibernate 3.0.5. And have tried most of the obvious approaches.

from Users where roles in('ADMIN') gives a JDBC error. from Users u where u.roles in('ADMIN') gives a class cast exception

I think this may be a problem with this particular version of hibernate.

解决方案

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')"

这篇关于HQL如何查询String的ElementCollection的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆