title: Query scalar collections in HQL
body: <p>I have the following class:</p>
  
  <pre><code>class User {
  String username;
  @CollectionOfElements
  private Set&lt;String&gt; roles = new HashSet&lt;String&gt;();
  [many more things here]
  }
  </code></pre>
  
  <p>And I want to write a HQL query that retrieves the username and the roles for all the users.</p>
  
  <pre><code>Query query = session.createQuery("select distinct u.username, u.roles from User u");
  </code></pre>
  
  <p>But it does not work, it throws the following exception:</p>
  
  <pre><code>org.hibernate.QueryException: not an entity [select distinct u.username,u.roles from com.eyeprevent.domain.users.User u]
  </code></pre>
  
  <p>Complaining that <code>u.roles</code> is not an Entity.</p>
  
  <p>How can I achieve what I want? (Querying <code>where u.roles='arole'</code> would be possible as well but again, it does not work).</p>