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).