Hi there,
I've recently started playing with the query by example component of the Criteria API.
My scenarios is as follows:
I have a class A, which as one of its properties has a set of instances of class B (Set<B> listOfBs).
I was hoping to set a criteria query on an example instance of B, for example all B's with a property value of "somevalue" and then find all A's that have such a B in their set:
Code:
Criteria aCrit = session.createCriteria(A.class);
A aExampleInstance = new A();
Example aExampleCriteria = Example.create(aExampleInstance );
Criteria bCrit = atCrit.createCriteria("listOfBs");
B bExampleInstance = new B();
bExampleInstance .setProperty("somevalue");
bCrit.add(Example.create(bExampleInstance ));
List<A> results = aCrit.add(aExampleCriteria).list();
I am using XML mapping, and A is mapping B as follows (A.hbm.xml):
Code:
<set name="listOfBs" table="B" inverse="false" cascade="all" lazy="true">
<key column="A_ID" not-null="true"/>
<one-to-many class="B"/>
</set>
I realize that this might not be the right approach - any better suggestions are welcome. The trouble is that I get an exception:
Quote:
org.hibernate.QueryException: could not resolve property: _com of: B
There is no such property name declared in any of my classes - so I am wondering if this may be a hibernate issue? Is there a workaround, or perhaps a resolution in a newer version? How can I proceed? I am using Hibernate 3.6.6.
Thanks