I use Hibernate in Java to map classes to DB tables. I have a Person table, each entry contains many pets, each of which has many toys.
I would like to be able to filter them in my DAO based on the attributes of the toys; for example, find all people with pets who have red toys like List<Person>. How can I filter this out?
Character class:
@Entity
public class Person {
...
@OneToMany(mappedBy = "person")
private List<Pet> pets;
...
}
Pet class:
@Entity
public class Pet {
...
@OneToMany(mappedBy = "pet")
private List<Toy> toys;
...
}
Toy Class:
@Entity
public class Toy {
...
private String colour;
...
}
source
share