Imagine the following class:
Code:
public class Cat {
List kittens;
String name;
//getters and setters
}
Now the following java code:
Code:
kitten1 = new Cat();
kitten2 = new Cat();
parent = new Cat();
parent.setKittens(new ArrayList());
parent.getKittens().add(kitten1);
parent.getKittens().add(kitten2);
// somehow saving the parent with its kittens ...
...
Does the following query work? I got errors when trying to compare with a List.
Code:
...
Query q = session.createQuery("
from Cat c where c.kittens = :kittens");
q.setParameter("kittens", parent.getKittens());
Cat result = q.list().get(0);