-->
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: Adding to existing bags
PostPosted: Wed Nov 02, 2005 6:16 pm 
OK...

I have a class 'Summary' that has an IList that holds a list of 'Project' classes, representing a one-to-many relationship. This is mapped correctly and saving a Summary causes the list of Project classes to to be saved to the database correctly as well.

The Problem: if I programmatically add a Project to the Summary class's IList, then try to save the Summary class, I get a Foriegn Key violation in my database because the Project's SummaryID field is still 0 (it never gets set)

Now, I understand that this doesn't make much sense, becuase in a normal situation, I should be able to just set the SummaryID property of the Project class when I add it to the Summary class's IList.

However, in this particular situation that will not work because I am serializing these object from XML which user's need to modify in a disconnected environment, so I am unable determine what value the database will assign for the ID fields, as I am using identities

Is there a way to get around setting the ID feilds of an object that Is being added to the collection of another object that is already in the database?


Top
  
 
 Post subject:
PostPosted: Thu Nov 03, 2005 12:01 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Can you just use a reference to a Summary instead of SummaryID in your Project class? And probably map summary-to-projects association using inverse="true". You will still have to ensure that projects and summaries are linked correctly after de-serialization, but it's outside the scope of NHibernate.


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.