-->
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.  [ 2 posts ] 
Author Message
 Post subject: Hibernate.initialize method clarification
PostPosted: Wed May 17, 2006 11:44 am 
Newbie

Joined: Wed May 03, 2006 6:25 am
Posts: 4
Hibernate version: API Documentation (3.2.0.cr1)

I wonder if anyone could please clarify the note for the Hibernate.initialize method:-

Note: This only ensures intialization of a proxy object or collection; it is not guaranteed that the elements INSIDE the collection will be initialized/materialized.

It reads as though the proxy object or collection can be initialized but the elements inside may not be initialized/materialized?

Under what condition would that occur?

I was looking for a way to see if lazy loaded properties and collections etc. have been loaded or are ready to be lazily loaded if accessed so I could reconnect back to a disconnected session.

Thanks...


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 17, 2006 12:46 pm 
Expert
Expert

Joined: Tue Apr 25, 2006 12:04 pm
Posts: 260
When you specify lazy="true" on collection elements, hibernate only returns proxy to each of collection objects - in other words, no database query for collection object.

If you close the session and try to access the collection object outside session, you will get LazyInit...Exception. In order to remove such exception either load the collection forcefully in one session by calling Hibernate.initialize( collection ) or connect to a new session with session.lock( mpObject, LockMode.NONE ). There are other options such as session.read(), session.merge() which will take one more query to load the information. Once locking the object in the second session, you can access the collection object without any exception. hope this helps...


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