Maybe you could use Query by example.
You can create an empty Cat object and insert the values that you would like to discriminate on: Ex;
Let's say you want to search for all cats named Teddy, you could do:
Code:
Cat searchCat = new Cat();
cat.setName("Teddy");
Collection cats = session.createCriteria(Cat.class).addCriteria(Example.add(searchCat)).list();
(I am not sure if this code compiles, but it should be pretty close :)
You need to validate if you can do the following:
Code:
Cat searchCat = new Cat();
Cat kittenCat = new Cat();
cat.setName("Teddy");
kittenCat.setName("Donald");
cat.addKitten(kittenCat)
session.createCriteria(Cat.class).addCriteria(Example.add(searchCat)).list();
I am not sure if you can specify criterias in associated classes. Let me know if it works as well.
This way, you would not have to manage how many criterias have been entered for the search query. It would automatically be handled by Hibernate.
If you can't use the Query by example, I think you will have to check for every possible search criteria and manage it if it is specified.
Good luck,
Vincent.