-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Mapping One Class to Multiple Tables
PostPosted: Mon Nov 08, 2004 2:16 pm 
Newbie

Joined: Mon Nov 08, 2004 2:08 pm
Posts: 1
Our screens represent multiple tables typically. What's the best approach for Hibernate in this case? Can we use one class which maps to multiple tables? Performance hit?

Development time is the BIG factor here..

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 08, 2004 7:14 pm 
Beginner
Beginner

Joined: Sun Oct 03, 2004 8:50 am
Posts: 32
Location: McLean, VA
In Hibernate 2 you can't map a single POJO to muliple tables, but there are a few things you might do.

If your tables represent some sort of hierarchy such as table A relates to B and C and table B relates to D and E, you easily map this using associations and then just fetch/persist the object representing A.

A slight twist on the above approach is if you have objects in the sort of hierarchical relationship described above but you want to expose some API that access these objects as if they were a single flat object. In this case you can use an Adapter design pattern. You adapater exposes a flattened object that then translates these calls into some sort of call that traveres your hierarchy of objects. For example, if you have a person object that has address objects you migh expose a person adapter where the getZipCode method actually calls person.getAddress().getZipCode().

If you have a bunch of objects that don't share that sort of hierarchal relationship you can write a single wrapper object that just delegates calls to individual objects that represent tables. Basically just like the adapter but instead of just wrapping one object it wraps many.

_________________
- Chad


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.