I'd like to search my data source for all object instances based on the values of an object related by association. The data model can be simplified to: object of type A holds a list of objects of type B. The goal is to find all instances of A where A contains a B such that B has a property value of X.
I can already successfully achieve this using Criteria queries as follows:
List<A> results = session.createCriteria(A.class)
.createCriteria("listOfBs")
.add(Restrictions.eq("propertyInB", x))
.list();
This is a simplification, and multiple properties of B will apply - the search functionality is necessary for a user populated filter.
I would like to replace this approach with query by example - where I'd simply create an object graph with the desirable parameters. My attempt in following the Hibernate docs failed, and is described in this question.
I thought that it might be helpful to demonstrate what I'm trying to achieve in a manner that works, and then seek equivalents - that's why I'm re-asking the question.
In short, my question is: How would you implement the above Criteria Query as a Query by Example in Hibernate? I'm using Hibernate 3.6.6.
Thanks!