I have an object called SearchCriteria with about 20 attributes, each one being a criteria via which one could search.
I need to build a db query based on any of these criteria. I'd like to programmatically loop through the object's attributes testing each one for null and then taking action on the ones that are not null. How do you programmatically loop through an object's attributes?
You could do this with reflection. But I think you could come up with a better solution. Hibernate has a criteria class. You could look at that.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Joined: Jun 22, 2009
I can definitely do this using hibernate restrictions, but the difficulty is that these criteria come from up to 7 tables and in order to be able to use the restrictions I need to fetch join all 7 tables. I'm only displaying data from 2 of these tables so why do the huge fetch? Big waste of resources.
So I'm trying to come up with a different way of finding the objects.