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: Cascade Updates To Proxied Class Not Working
PostPosted: Thu Jan 31, 2008 4:37 pm 
Newbie

Joined: Mon Apr 30, 2007 6:17 pm
Posts: 14
I have the following mapping:

ClassA map has:

- a bag of ClassB (lazy="true", cascade="all-delete-orphan", inverse="true")

ClassB map has:

- a many-to-one property of ClassC (lazy="proxy", cascade="none")

ClassC map has:

- a bag of ClassD (lazy="true", cascade="all-delete-orphan", inverse="true")

We have recently realized that sometimes when changing and saving an instance of ClassA, we also need to add an item to ClassC's collection of ClassD. Or sometimes we need to change a property of ClassD in an item already existing in that collection.

So I changed the many-to-one property of ClassC in the ClassB map to cascade="save-update". That should do it, right.? It does not. If I also change lazy="false" on that many-to-one property, then it works fine.

It seems like NHibernate is not detecting when a proxied class has changed so that it can cascade the updates. I'm sure I'm missing something simple. Ideas?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 31, 2008 5:03 pm 
Expert
Expert

Joined: Tue Aug 23, 2005 5:52 am
Posts: 335
Since the relationship for the Class D collection on Class C is marked as inverse=true no changes to the collection will be persisted. You need to change the C property of the class D objects (although you haven't shown it in your example).

Only one end of a bidirectional association can be persisted and you've marked your collection as the non-persistent end. If you want the collection to be persistent you need to remove the inverse=true

Cascading is separate issue that many stumble over. It's worth re-reading the sections on cascading and the inverse attribute in the documentation.

Cheers,

Symon.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 31, 2008 5:35 pm 
Newbie

Joined: Mon Apr 30, 2007 6:17 pm
Posts: 14
Symon,

Thanks for the reply. The ClassD collection must be inverse because the foreign key in the table from class D to class C is not nullable. However, that should not be a problem because here's how I add a ClassD item to the collection in ClassC:

Code:
public virtual void AddClassD(ClassD item)
{
    item.ClassC = this;
    classDList.Add(item);
}

This is a well worn pattern and works fine. When I save a ClassC directly, ClassD persists just fine. The place that things are breaking down I believe is the many-to-one association to ClassC from ClassB. It is not cascading save-updates because of the lazy proxy. As I mentioned, when I change ClassC to not lazy in the ClassB map, all is well.

Tim


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.