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.  [ 3 posts ] 
Author Message
 Post subject: How to ignore / not update a child bag collection?
PostPosted: Wed Jun 20, 2007 5:34 am 
Beginner
Beginner

Joined: Thu Oct 26, 2006 4:45 am
Posts: 39
Hibernate version: 1.0.4

Mapping documents:

A pretty complex mapping for a (parent-)hotelobject with a few BAGged collections.

One of the bags is:

<bag name="RoomsUntyped" outer-join="true" fetch="join" lazy="false" cascade="none" inverse="true">


Code between sessionFactory.openSession() and session.close():

..SaveOrUpdate(hotel)

I came across the following situation:

I want to save-update the parent-object Hotel, but is there a way to tell NHibernate in c# code to ignore the Rooms collection for just this time?

That is, sometimes in code I do want the room-collection to be saved to the database, which can mean deleting some child-objects if necessary, but in another scenario that particular collection should be ignored when saving/updating the parent hotelobject because only other fields of parent-object must be updated.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 20, 2007 1:46 pm 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
By default, with what you mapped, it won't propagate/cascade anything since you put cascade="none".

From what I remember, it's not possible without using a very tricky way (I already asked the question some months ago), though I'm using Hibernate and not NHibernate.

But I'm not sure this trick is even possible with NHibernate since it's based on the 2.x version of Hibernate, and not the last one (3.x).

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject: Re: How to ignore / not update a child bag collection?
PostPosted: Thu Jun 21, 2007 3:08 pm 
Expert
Expert

Joined: Fri May 13, 2005 11:13 am
Posts: 292
Location: Rochester, NY
hace_x wrote:
<bag name="RoomsUntyped" outer-join="true" fetch="join" lazy="false" cascade="none" inverse="true">


Since you are not using cascades and the collection is inverted, you should be able to acheive what you want by evicting them from the session. (ISession.Evict())


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