I'v used hibernate mapping in one of my web application. I found 'one-to-many' mapping very handy as it represents most of my class relationships.
For instance, I've got class Jurisdiction, Location, Contact. Each jurisdiction has more than one locations and each location has more than one contacts. What I've done at the moment is:
class Jurisdiction{ List locations; }
class Location{ List contacts; }
In my hibernate mapping file, a one-to-many mapping is made between Jurisdiction and Location, as well as Location and Contact.
So if I set lazy to false, once I load a Jurisdiction object, all locations belong to this jurisdiction and all contacts belong to those locations are all loaded. Sometimes it's almost a whole dump of my database.
I'm just wondering if the one-to-many is a proper way to map this kind of relationship, but on the programming side, it's very handy, I can just get the root object, and all details of the sub objects are available in a list.
However, someone has suggested that I should not do that, if I need the locations of a jurisdiction, just do another query, don't make it as a list of Jurisdiction class.
I would be happy if someone can have a bit discussion of this, is the latter way I commented the general use of hibernate?
|