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
|
|