First off, congrats on the amazing effort by the Hibernate team. It's simplified our application in so many ways.
I'm trying to use the Criteria API to search nested properties of a class. This is a topic that's been covered in this forum before, but I haven't found this PARTICULAR question.
The simplest way to describe the problem would be to use the Cat/Kitten analogy from Chapter 14 of the hibernate docs....
Code:
List cats = sess.createCriteria(Cat.class)
.add( Expression.like("name", "F%")
.createCriteria("kittens")
.add( Expression.like("name", "F%")
.list();
This gives back all the cats starting with 'F' who have kittens that start with 'F'.
The question is, what code would you add to return all the cats starting with 'F' who have kittens starting with 'F' AND kittens starting with 'G'?
My application has nothing to do with cats, but the relationships are pretty much same.
I've tried creating a conjunction/disjunction, on the "kittens" criteria, but the resulting sql basically tried to find a single kitten named 'F%' AND 'G%', which is obviously impossible.
I've tried creating two criteria objects (both kittens), but the resulting sql is incorrect. The joins get messed up because of the like-named criteria, I guess. Here's the code for that case...
Code:
Criteria cats = session.createCriteria( Cat.class);
cats.add( Expression.like("name", "F%"));
Criteria k1 = cats.createCriteria("kittens");
k1.add( Expression.like("name", "F%"));
Criteria k2 = cats.createCriteria("kittens");
k2.add( Expression.like("name", "G%"));
Thanks for any advice....I feel like I've exhausted my options.