-->
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.  [ 1 post ] 
Author Message
 Post subject: How to avoid initializing associations?
PostPosted: Thu Apr 15, 2010 10:15 am 
Beginner
Beginner

Joined: Thu Feb 08, 2007 10:40 am
Posts: 46
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?


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

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.