Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Finding attributes in an object

 
Tanya Ruttenberg
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

TDR
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Tanya Ruttenberg
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ireneusz Kordal
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic