-->
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.  [ 5 posts ] 
Author Message
 Post subject: Error while saving two entities with a many-to-one
PostPosted: Tue Aug 16, 2005 5:57 am 
I have two related tables:

Code:
<class name="Center" table="Center">
  <id name="Id" column="CenterID" unsaved-value="0">
   <generator class="identity" />
  </id>
  <property name="Name" type="String" length="25" not-null="true" />
  <many-to-one name="Region" column="RegionID" class="Region"
               not-null="true" />
</class>


Code:
<class name="Region" table="Region">
  <id name="Id" type="Int32" column="RegionID" unsaved-value="0">
   <generator class="identity" />
  </id>
  <property name="Name" type="String" not-null="true" />
  <set name="Centers" inverse="true" lazy="true" cascade="all">
    <key column="RegionID" />
    <one-to-many class="Center" />
  </set>
</class>


Why an error occurs when I call save() only once?

Code:
Center c = new Center();
c.Name = "ccc";
Region r = new Region();
r.Name = "rrr";
r.CreditCenters.Add(c);
session.Save(r);


Best regards,
Sergey


Top
  
 
 Post subject: small error
PostPosted: Tue Aug 16, 2005 5:59 am 
The c# should look so:

Code:
Center c = new Center();
c.Name = "ccc";
Region r = new Region();
r.Name = "rrr";
r.Centers.Add(c);  // instead of r.CreditCenters.Add(c);
session.Save(r);


Top
  
 
 Post subject:
PostPosted: Tue Aug 16, 2005 11:35 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
Can you post the content of the file "log.txt" (after enabling DEBUG in log4net configuration) ?

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject: 2KPixel: thanks
PostPosted: Wed Aug 17, 2005 12:06 pm 
The problem was with "not null column" .
But I still have misunderstanding of some simple concepts of O/R mapping, with are realized in NH, for example:
http://nhibernate.sourceforge.net/forum ... .php?t=599


Top
  
 
 Post subject:
PostPosted: Mon Sep 26, 2005 2:03 pm 
Newbie

Joined: Mon Sep 26, 2005 1:42 pm
Posts: 2
Hi,

I have the same problem. Did you find the solution for that problem. At the moment it is the K.O. criterium for me not to use NHibernate.


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