-->
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: Solutions on Lazy fetching (open session vs closed )
PostPosted: Sat Apr 29, 2006 12:27 pm 
Newbie

Joined: Tue Apr 04, 2006 1:00 pm
Posts: 8
Hi!

I've just been struggling with Hibernates lazy fetch consept vs closed Sessions, but I think I found an solution (at least for now) though.

The solution I'm going for is to use Hibernate.initialize( obj ) on objects/collections before I close the session, but this made me start thinking; how is actually Hibernate.initialize( obj ) working ?

I mean: The reason we dont use lazy=false on associations is the risk (in worst case) for Hibernate to fetch the whole database - right?
But how is Hibernate.initialize working vs lazy=false on associations?

To clarifying what I am talking about:
I have a method where I am receiving a List with User object. To access/use objects or accociations from that list I need to use Hibernate.initialize on those objects/collections like this:

Code:
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
      session.beginTransaction();

      List list = session.createCriteria(Project.class).setCacheable(true).list();
      
      // Initializing the Objects needed within the list
        for ( int i = 0; i < list.size(); i++ ){
           Project p = (Project) list.get( i );
           Hibernate.initialize( p.getUsers() ); // another list
           Hibernate.initialize( p.getUser() ); // obj
           Hibernate.initialize( p.getClient() ); // obj
        }
      
      session.getTransaction().commit();
       
      return list;


What is Hibernate.initialize doing, and how deep within the object-graph does it affect?

Here is an article I found on the issue for people with the lazy fetch problem :

http://www.javalobby.org/java/forums/t20533.html

Thanks in advance


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 10, 2006 6:20 pm 
Newbie

Joined: Wed Apr 20, 2005 6:57 pm
Posts: 9
Location: San Diego, Ca
I'm not sure exactly what you were asking here. But if you were asking what's the difference between lazy=true and then calling initialize(). If A is the parent object and it has collections of B and C. And these collections were non lazy and B and C had collections D and E that were non lazy, anytime you loaded A you'd end up loading A,B,C,D,E. Actually, you'd load A and MANY of the rest. On the other hand make them all lazy and you load them with initialize() as needed thereby making A load faster, so you're not waiting around for everything to finish loading before you can do anything in the gui. Hope this is helpful.


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.