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: Eager loading issue
PostPosted: Mon Jul 17, 2006 11:38 am 
Beginner
Beginner

Joined: Tue Jan 17, 2006 12:55 pm
Posts: 49
I am using a disconnected type design in my app whereby I get my objects from a repository which loads the objects with the required object graph , closes the session, and returns the objects to the client.

I get a "Failed to lazily initialize a collection - no session" even when I have explicitly told NHibernate to do a Join using the following code:

Code:
                ICriteria criteria = localSession.CreateCriteria(typeof (Document));
                criteria.Add(Expression.Eq("DocumentID", documentID));
                criteria.SetFetchMode("Attributes", FetchMode.Join);
                criteria.SetFetchMode("Rfi", FetchMode.Join);
                criteria.SetFetchMode("Rfi.SubProject", FetchMode.Join);
                criteria.SetFetchMode("Rfi.SubProject.AttributeDefinitions", FetchMode.Join);
                criteria.SetFetchMode("Rfi.SubProject.DocumentNamingFormats", FetchMode.Join);
                criteria.SetFetchMode("Rfi.SubProject.AllowedOrganisationDisciplines", FetchMode.Lazy);
                criteria.SetFetchMode("Rfi.SubProject.AllowedTransmittalTypeRecipientTransmittalPurposes", FetchMode.Lazy);
                criteria.SetFetchMode("Rfi.SubProject.AllowedTransmittalTypes", FetchMode.Lazy);
                criteria.SetFetchMode("Rfi.SubProject.DocumentSubTypes", FetchMode.Lazy);
                criteria.SetFetchMode("Rfi.SubProject.AllowedDocumentTypeDocumentSubTypes", FetchMode.Lazy);
               
                criteria.SetResultTransformer(CriteriaUtil.DistinctRootEntity);

                results = criteria.List();


I even tried the nasty hack of iterating through the collection to ensure the collections are loaded:
Code:
//HACK: To get around the eager loading issue
                    foreach(object o in doc.Rfi.SubProject.DocumentNamingFormats)
                    {
                        //Do nothing
                    }

                    foreach(object o in doc.Rfi.SubProject.AttributeDefinitions)
                    {
                        //Do nothing
                    }

                    foreach(object o in doc.Attributes)
                    {
                        //Do nothing
                    }


Is this a bug or am I doing something unexpected?

The funny thing is there is a workaround that I can use in that if I copy an object into another new variable, this behaviour goes away... again, is this a bug or a feature?


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.