• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Taking Hibernate Relationships to a new (lower) level

 
chris gar
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • 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 ]
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • 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.
 
Praveen Kumar
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic