-->
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: Yet another newbies question abount cascading
PostPosted: Wed Jul 25, 2007 5:34 pm 
Newbie

Joined: Wed Jul 18, 2007 3:54 pm
Posts: 2
Hello,

I have a question about cascading. It is about a one to many relationship between Word and WordExpression. In the mapping file the cascade for the bag is set to save-update.

This code works just fine:

Code:

Word word = new Word();
word.Catalogue = "My new word";
word.Subject = new Subject(3);

WordExpression wordExpression = new WordExpression();
wordExpression.Catalogue = "Some expression #1 for new word";
wordExpression.Word = word;

word.WordExpressions.Add(wordExpression);

NHDataManager.Save(word, exchangeContext);


How can I avoid the assignment?

wordExpression.Word = word;

I thought NHibernate knows that fact because of the mapping file. Do I really have to assign for each new WordExpression the word manually or did I just missed some points here?

Thx 4 any help.


Top
 Profile  
 
 Post subject: Re: Yet another newbies question abount cascading
PostPosted: Wed Jul 25, 2007 9:57 pm 
Expert
Expert

Joined: Fri May 13, 2005 11:13 am
Posts: 292
Location: Rochester, NY
mosspower wrote:
How can I avoid the assignment?


You can't. However, you can clean things up in your domain objects by adding a method like this:

Code:
public void AddExpression(WordExpression w) {
   WordExpressions.Add( w );
   w.Word = this;
}


See here, especially the paragraph starting "To tighten things up a bit,..."


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 26, 2007 2:51 am 
Regular
Regular

Joined: Thu Nov 23, 2006 10:29 am
Posts: 106
Location: Belgium
If your WordExpressions-collection is mapped with the inverse attribute, you must use the assignment.

If it is not mapped inverse, then it will be updated without using that assignment, but 2 sql statements will be issued and you have the risk that you're violating not null constraints on your database (see the link marcal refers to).

_________________
Please rate this post if it helped.

X.


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.