【发布时间】:2011-03-26 06:49:27
【问题描述】:
我有以下课程:
class User {
String username;
@CollectionOfElements
private Set<String> roles = new HashSet<String>();
[many more things here]
}
我想编写一个 HQL 查询来检索所有用户的用户名和角色。
Query query = session.createQuery("select distinct u.username, u.roles from User u");
但它不起作用,它会抛出以下异常:
org.hibernate.QueryException: not an entity [select distinct u.username,u.roles from com.eyeprevent.domain.users.User u]
抱怨u.roles 不是实体。
我怎样才能实现我想要的? (查询where u.roles='arole' 也是可能的,但同样不起作用)。
【问题讨论】:
标签: java hibernate orm collections hql