I am trying to create example criteria for complex objects. I think that the problem boils down to being able to create example criteria for the POJO example of a cat's son/daughter-in-law (the mate of a kitten).
The following approach creates the correct SQL for properties set in the kitten, but ignores all properties set in the son-in-law (it adds AND (1=1) to the where clause).
Code:
Criteria catCriteria = session.createCriteria(Cat.class).add(Example.create(exampleCat));
if (exampleCat.getKittens() != null) {
for (Iterator iter=exampleCat.getKittens().iterator(); iter.hasNext();) {
Cat exampleKitten = (Cat) iter.next();
Criteria kittensCriteria = catCriteria.createCriteria("kittens").add(Example.create(exampleKitten));
if (exampleKitten.getMate() != null) {
// the following line has no affect. No matter what properties
//I set in the kitten's son-in-law, the hibernate query just adds and (1=1).
kittensCriteria.createCriteria("mate").add(Example.create(exampleKitten.getMate()));
}
}
}
[/i]