• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Taking Hibernate Relationships to a new (lower) level

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We are designing a database with this new-fangled Hibernate tool in mind.

The database has a ClientHeader object/table with fields like firstName, lastName, ssn, etc.

We also have a ClientDetails object with info like dob, weight, hairColor, etc.

Simple so far:

The ClientDetails object started off with a few object members (sets) like Adress, Contact Info (to hold multiple addresses, phone numbers etc). HOWEVER Now we have about 35 object members for ClientDetails ( like MilitaryHistory, Aliases, Children, blah, blah, blah.) The ClientDetails object is now HUGE!

I think we get an A+ for our object oriented thinking, but I think we've created a monster as far as Hibernate goes.

The question: If we define the relationships (as described above) is Hibernate going to look in all 35 (or 36 with parent) tables everytime we want to look at something in the ClientDetail table?

If we just want a zip code from ClientDetail.Address, do Hibernate have to look up every other table (MilitaryHistory, Children, Alias, and the other 30-some-odd) ?

Thanks
[ October 18, 2004: Message edited by: chris gar ]
 
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm just getting started now with Hibernate, but from what I've read you can set up lazy loading to avoid that situation. Hibernate initializes a ClientDetails object with empty Collection implementations that will load the related objects when you first access the Collection. You must make sure that the Session is still open when you do the access, but other than that it's seemless.
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We had a similar situation and we turned the lazy loading on all Sets, Lists. For many-to-one mappings we turned the object level lazy loading and saw tremendous increase in performance.

The only catch is that the session has to be kept open. We are following an approach called as "Hibernate Session per request". We open a new session per each request. You could also detach and attach objects across sessions.

Session.evict(Object) - detaches
Session.refresh(Object) - attaches

Hope this helps,

Praveen.
reply
    Bookmark Topic Watch Topic
  • New Topic