Hi,
the object I want to persist into the database is something like a tree node. It has a parent (which is of the same type) and a list of children (also of the same type). I would like to define a hibernate mapping, which maps the parent as a one to one association and the children as an inverse many to one association.
When I load an arbitrary tree node from the database, wouldn't that mapping immediately load all tree nodes from the database that are connected to my initial tree node on any path? I imagine that this would happen because hibernate fetches all associated objects and the associated objects from these objects and so on and so on.
Now one would probably say that this will not happen, because of lazy loading. That is fine, as long as I work on a 2-tier environment. However, I have a 3-tier environment, where the server serializes the loaded object and sends it to the client. During the serialization process, all lazy associations should be initialized and once again the whole database is sucked into the server.
How can I avoid this? Is there any way to map an association and then tell hibernate to not initialize that association for a given object?
|