| Hey Guys,
 Just been frustrated, day after day with a question. Supposed we have something like this.
 
 class Cat{
 ...
 List <Mouse> mice;
 List <Toys> toy;
 
 
 ...
 @OneToMany(cascade=CascadeType.ALL)
 public List<Mouse> getMice() {
 return mice;
 }
 
 
 @OneToMany(cascade=CascadeType.ALL)
 public List<Toy> getToy() {
 return toy;
 }
 }
 
 Now say I wanna do a criteria query in order to get a cat with id 1 (so I get one cat). But instead of getting all the mice and toys, I wanna get only the mice whose size property is "big", and only those toys whose color property is "blue".
 
 Everytime I do something like this, it doesn't work because the second criteria I create becomes a subcriteria. Can anyone help?
 
 Here is the code I've been trying.
 
 Long catId = new Long(1);
 session.createCriteria(Cat.class).add(Restrictions("catId", catId)
 .createCriteria("mice", Criteria.Left_Join).add(Restriction("size", "big"))
 .createCriteria("toy", Criteria.Left_Join).add(Restrictions("color", "blue")).uniqueResult();
 
 Now obviously this won't work because hibernate thinks color is for the mice criteria. So any ideas as to how to accomplish what I am trying to accomplish? Thank you.
 
 
 Bear
 
 
 |