-->
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: How does Hibernate.Initialize() work?
PostPosted: Wed Sep 21, 2005 3:35 pm 
Beginner
Beginner

Joined: Tue Oct 26, 2004 4:59 pm
Posts: 23
Hibernate version: 3.05

Just a couple quick questions.

1) If I have a lazy class and call Hibernate.Initialize() on an instance of it, will the entire object including any collections also be loaded from the database?

2) How come if I use load() to get an object from the database is it still lazily loaded? If I am asking for a specific instance shouldn't it be assumed that I really do want it? It seems a waste to have to call initialize() on an object I loaded so it will be available on the jsp.

Thanks,
Karl


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 21, 2005 6:06 pm 
Expert
Expert

Joined: Wed Apr 06, 2005 5:03 pm
Posts: 273
Location: Salt Lake City, Utah, USA
1. It shouldn't be hard to just try this out and see, but I believe only the object itself will be initialized, collections will still remain lazy-loaded (won't load until you ask for them).

2. One use-case for this behavior is deleting objects. If you have to load the entire object before deleting it, it's two round-trips. Since load() returns a proxy (doesn't hit the database), you can then delete it, and no select occurs before the delete. You can use get() if you want it to be loaded immediately.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 22, 2005 1:25 pm 
Beginner
Beginner

Joined: Tue Oct 26, 2004 4:59 pm
Posts: 23
I did try the first one, and you are correct.

Thanks for the tip on get(). The API verbage is almost identical between load() and get() except it says get() returns null if the object can't be found. So I just assumed other than that, the methods did the same thing.

Thanks,
Karl


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.