Compound key sleep mode task

I got this hibernation mapping:

<class name="CoverageTerm" table="coverage_term"> <composite-id name="id" class="CoverageTermPK"> <key-many-to-one name="productTerm" class="ProductTerm"> <column name="termtype_id"></column> <column name="product_id" ></column> </key-many-to-one> <key-many-to-one name="productCoverage" class="ProductCoverage" column="product_coverage_id"></key-many-to-one> </composite-id> <property name="data"/> </class> 

This is a simple compound keyword mapping to a relation to table productCoverage and a compound key relation to productterm.

Now the problem arises in my search function:

 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(); } 

This should allow me to make the subcriteria on "id" (which is the main key, CoverageTermPK) and add restrictions to it, but when I start it, I get an error message:

 org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.hibernate.QueryException: could not resolve property: productTerm of: CoverageTerm 

You feel weird, shouldn't I get CoverageTermPK there? If I try to use the subcriteria in the data property, the criteria will work, I just can not get PK in the id sub-critique.

Any ideas as to why this is happening?

+4
source share
1 answer

Not sure about your specific class structure, but try adding id this way instead of separate criteria:

 Restrictions.eq("id.productTerm", productTerm); Restrictions.eq("id.productCoverage", productCoverage); 
+12
source

All Articles