-->
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.  [ 3 posts ] 
Author Message
 Post subject: Java bject references another (simple question)
PostPosted: Sun Jul 15, 2007 12:15 pm 
Newbie

Joined: Sun Jul 15, 2007 12:06 pm
Posts: 1
Hello All, I want to load an object (say parent) from the database. It references another object (say child) (which is also stored in the database in a different table). When I load the parent object, Hibernate automatically instantiates the child too, which is fantastic.

How would I handle those cases where the child already exists in memory and I don't want hibernate to load the child when I load the parent ?

Thanks for your time, Bhishma


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 15, 2007 1:41 pm 
Regular
Regular

Joined: Fri May 12, 2006 4:05 am
Posts: 106
It depends on whether the child is already attached to the Hibernate persistence-context or not.
If the persistence-context knows about the child-object because you retrieved it via hibernate, then you don't have to do anything - hibernate won't load the child-object again and your parent-object will reference the exact child-instance you retrieved before.
If the child-object is in detached state (i.e. not contained in the persistence-context) you won't be able to avois a database-hit. If you reattach the child via saveOrUpdate() hibernate will also have to look up the child-object in the database to see whether it's dirty or not.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 16, 2007 2:37 am 
Senior
Senior

Joined: Thu May 17, 2007 2:31 am
Posts: 194
Location: Sri Lanka
Hi

You can use lazy="true" in your child collection . then hibernate load child collection at the time you use it. Use some second level caching.



Amila

(Don't forget to rate if helps)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.