-->
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: Clear a collection (bag) with lazy=true
PostPosted: Tue Jan 02, 2007 12:59 pm 
Newbie

Joined: Tue Jan 02, 2007 12:34 pm
Posts: 1
Hibernate version:
1.0.3.0
Mapping documents:

In Parent

<bag name="Childs" inverse="true" lazy="true" cascade="all-delete-orphan">
<key column="ID_PARENT"/>
<one-to-many class="Eg.Child"/>
</bag>

In Child :

<many-to-one name="Parent" class="Eg.Parent" column="ID_PARENT" />



Code between sessionFactory.openSession() and session.close():
just a session.Get


Full stack trace of any exception that occurs:
Failed to lazily initialize a collection - no session

Name and version of the database you are using:
Sql Server 2005



Hello,

I cannot clear a child collection from the parent without loading the collection. For example (assuming p was loaded with a session.Get)

p.Childs.Clear();
session.Update(p);

I would like to avoid the creation of a special query with left join fetch and I want to keep the lazy=true, is it possible ?

In my Parent.cs class, Child property is a IList (System.Collections.IList).

Thanks for your help

Gengis


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 14, 2007 10:38 am 
Newbie

Joined: Wed Nov 08, 2006 7:55 am
Posts: 4
because,set "lazy=true", so, When you get the object ,it is details is lazy.

to solve your problem, you should set FetchMode to eager your details,
or Call NHibernateUtil.initailObj to eager your details, then you can
via the details attibute ,and call it is clear() method.


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.