title: How to query for map element in hibernate?
body: <p>I have a hibernate mapping which looks like this:</p>
  
  <pre><code>&lt;hibernate-mapping&gt;
      &lt;class name="MutableEvent" table="events"
          mutable="true" dynamic-insert="true" dynamic-update="true"&gt;
  
          &lt;id name="id"&gt;
              &lt;generator class="assigned" /&gt;
          &lt;/id&gt;
          &lt;property name="sourceTimestamp" /&gt;
          &lt;property name="entryTimestamp" /&gt;
  
          &lt;map name="attributes" table="event_attribs"
              access="field" cascade="all"&gt;
              &lt;key column="id" /&gt;
              &lt;map-key type="string" column="key" /&gt;
              &lt;element type="VariantHibernateType"&gt;
                  &lt;column name="value_type" not-null="false" /&gt;
                  &lt;column name="value_string" not-null="false" /&gt;
                  &lt;column name="value_integer" not-null="false" /&gt;
                  &lt;column name="value_double" not-null="false" /&gt;
              &lt;/element&gt;
          &lt;/map&gt;
  
      &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>Storing and loading of my Object works fine. The question I have, is querying for maps in hibernate supported, and how would I do it using the criteria api?</p>
  
  <p>I want to do something like this (this is actually a part of my testcase):</p>
  
  <pre><code>...
  m.getAttributes().put("other", new Variant("aValue"));
  this.storeEvent(MutableEvent.fromEvent(e));
  getSession().clear();
  MutableEvent m = (MutableEvent) getSession().get(MutableEvent.class, e.getId());
  Assert.assertNotNull(m.getAttributes().get("other"));
  Assert.assertEquals(new Variant("aValue"), m.getAttributes().get("other"));
  Assert.assertNull(m.getAttributes().get("other2"));
  getSession().clear();
  crit = DetachedCriteria.forClass(MutableEvent.class);
  crit.add(Restrictions.eq("attributes.other", new Variant("aValue")));
  List l = this.findByCriteria(crit);
  Assert.assertEquals(1, l.size());
  </code></pre>
  
  <p>The important part is, this fails with "Could not resolve property: attributes.other":</p>
  
  <pre><code>crit.add(Restrictions.eq("attributes.other", new Variant("aValue")));
  List l = this.findByCriteria(crit);
  </code></pre>
  
  <p>Is there a solution for that problem at all?</p>
  
  <p><strong>Update</strong></p>
  
  <pre><code>List l = find("from MutableEvent M where M.attributes['other'] = ?", new Variant("aValue"));
  </code></pre>
  
  <p>The above code doesn't throw a exception, but the query itself is still not what I want to have. I created a custom type as one may see by the mapping, actually I would want to query for a string (column value_string) but any attempt to modify the query to access a part of the type like in <em>"from MutableEvent M where M.attributes['other'].string = ?"</em> doesnt work. So how would I query for a part of a component?</p>
  
  <p>The Type is implemented like this:</p>
  
  <pre><code>...
  private static final String[] PROPERTY_NAMES = { "type", "string", "integer", "double" };
  
  public String[] getPropertyNames() {
      return PROPERTY_NAMES;
  }
  ...
  </code></pre>