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: lazy load failed to initialize - no session or session...
PostPosted: Mon Jun 01, 2009 11:26 am 
Newbie

Joined: Thu May 14, 2009 4:19 am
Posts: 12
I've seen this question a few times, generally answered with 'the session has been closed so you need to open it'

In this scenario -
Class Order
{
int Id
IList<Item> Items;
}
Class Item
{
int Id
string Name;
}

if All Orders are loaded
IList<Order> itemList;
using(ISession session = _sessionFactory.OpenSession())
{
ICriteria targetObjects = _session.CreateCriteria(typeof(Order));
itemList = targetObjects.List<Order>();
}
and the Items are Lazy Loaded
Then having the following
itemList[0].Items[0].Name will result in an exception - failed to lazily initialize a collection of role....

Is there a way to configure the Mapping File, maybe using a Proxy, so that the Session is Automatically Opened to load the Items for that Order when accessed?

thanks


Top
 Profile  
 
 Post subject: Re: lazy load failed to initialize - no session or session...
PostPosted: Fri Jun 05, 2009 2:14 pm 
If I understood your question, you can use
lazy="true", on your mapping files.

[]s


Top
  
 
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.