开发者

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.

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.

How can I achieve what I want? (Querying where u.roles='arole' would be possible as well but again, it does not work).


Are you looking for this:

select u.username 
  from User u
 where :role in elements(u.roles)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜