[英]Query scalar collections in HQL
I have the following class: 我有以下课程:
class User {
String username;
@CollectionOfElements
private Set<String> roles = new HashSet<String>();
[many more things here]
}
And I want to write a HQL query that retrieves the username and the roles for all the users. 我想编写一个HQL查询来检索所有用户的用户名和角色。
Query query = session.createQuery("select distinct u.username, u.roles from User u");
But it does not work, it throws the following exception: 但它不起作用,它抛出以下异常:
org.hibernate.QueryException: not an entity [select distinct u.username,u.roles from com.eyeprevent.domain.users.User u]
Complaining that u.roles
is not an Entity. 抱怨
u.roles
不是实体。
How can I achieve what I want? 我怎样才能实现我的目标? (Querying
where u.roles='arole'
would be possible as well but again, it does not work). (查询
where u.roles='arole'
也是可能的,但是再次,它不起作用)。
Are you looking for this: 你在找这个:
select u.username
from User u
where :role in elements(u.roles)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.