• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Finding attributes in an object

 
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
 
Bartender
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.
 
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
She's out of the country right now, toppling an unauthorized dictatorship. Please leave a message with this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic