title: Hibernate criteria problem with composite key
body: <p>I got this hibernate mapping:</p>
  
  <pre><code>&lt;class name="CoverageTerm" table="coverage_term"&gt;
  
      &lt;composite-id name="id" class="CoverageTermPK"&gt;
          &lt;key-many-to-one name="productTerm" class="ProductTerm"&gt;
              &lt;column name="termtype_id"&gt;&lt;/column&gt;
              &lt;column name="product_id" &gt;&lt;/column&gt;
          &lt;/key-many-to-one&gt;
          &lt;key-many-to-one name="productCoverage" class="ProductCoverage" column="product_coverage_id"&gt;&lt;/key-many-to-one&gt;
      &lt;/composite-id&gt;
  
      &lt;property name="data"/&gt;
  &lt;/class&gt;
  </code></pre>
  
  <p>This is a simple composite key mapping with a relation to table productCoverage and a composite key relation to productterm.</p>
  
  <p>Now the problem comes in my search function:</p>
  
  <pre><code>public CoverageTerm getCoverageTermFromProductTermCoverage(ProductTerm productTerm, ProductCoverage productCoverage) {
      Criteria critCt = getSession().createCriteria(CoverageTerm.class);
      Criteria critCtId = critCt.createCriteria("id");
      critCtId.add(Restrictions.eq("productTerm", productTerm));
      critCtId.add(Restrictions.eq("productCoverage", productCoverage));
      return (CoverageTerm) critCt.uniqueResult();
  }
  </code></pre>
  
  <p>This should let me make a subcriteria on "id" (which is the primary key, CoverageTermPK) and add restrictions on it, but when I run it I get the error message:</p>
  
  <pre><code>org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.hibernate.QueryException: could not resolve property: productTerm of: CoverageTerm
  </code></pre>
  
  <p>This feels strange, shouldn't it get the CoverageTermPK there? If I try with a subcriteria on the "data" property the criterias work, I just don't seem to be able to get the PK on the "id" subcriteria.</p>
  
  <p>Any ideas as to why this is happening?</p>