title: How to query distinct values from map with given key in Hibernate?
body: <p>I have following Hibernate 3 mapping for User class:</p>
  
  <pre><code>&lt;class name="org.test.User" table="users"&gt;
  
  ... some other mapping...
  
      &lt;map name="metadata" table="user_metadata"&gt;
          &lt;cache usage="transactional"/&gt;
          &lt;key column="user_id" not-null="true" foreign-key="FK_USERMETADATA_USER_ID"/&gt;
          &lt;map-key type="string" column="datum_key" length="255" /&gt;
          &lt;element type="string" column="datum_value" length="1024" not-null="true"/&gt;
      &lt;/map&gt;            
  &lt;/class&gt;
  </code></pre>
  
  <p>I would like to retrieve a list of all datum_values with given datum_key.</p>
  
  <p>In SQL the query would look like:</p>
  
  <pre><code>select distinct datum_value from user_metadata where datum_key = 'Member Type'
  </code></pre>
  
  <p>What would be the most feasible approach? Create a new Hibernate mapping for the user_metadata as well? Or try to come up a HQL/JPA QL query using indices/elements returning (possibly scalar) values? So far I tried HQL/JPA QL approach a bit and I did not get too far.</p>