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: cascading updates. identity value not propagating to child
PostPosted: Tue Oct 10, 2006 12:21 am 
Beginner
Beginner

Joined: Mon Oct 02, 2006 6:46 pm
Posts: 32
1.2.0 Beta:

I have an orders object that has a one-to-many relationship with my orderlines object. When I populate orders and its orderlines and call .Save on order (with cascade on) the orderid is generated for orders, but isn't propagated to orderlines and I get the "Cannot insert the value NULL into column" error.

Here are my mapping files:

Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
  <class name="HELM.Domains.Orders,HELM.Domains" table="orders" lazy="false">
    <id name="Orderid" column="Orderid" type="System.Int32">
      <generator class="native"/>
    </id>
    --<<...snipped out irrelevant fields...>>--
    <!-- Relationships-->
    <bag name="Orderlines" lazy="false" inverse="true" cascade="all">
      <key column="Orderid" />
      <one-to-many class="HELM.Domains.Orderlines, HELM.Domains" />
    </bag>   
  </class>
</hibernate-mapping>



Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
  <class name="HELM.Domains.Orderlines,HELM.Domains" table="orderlines" lazy="false">
    <id name="Orderid" column="OrderID" type="System.Int32">
      <generator class="assigned"/>
    </id>
    --<<...snipped out irrelevant fields...>>--
    <property column="OrderLineID" name="OrderLineid" type="System.Int32" not-null="true"/>
  </class>
</hibernate-mapping>



appreciate any help.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 10, 2006 12:41 am 
Regular
Regular

Joined: Tue Feb 21, 2006 9:50 am
Posts: 107
did you place a many-to-one relationship in your orderline mapping? It should look like this:

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
  <class name="HELM.Domains.Orderlines,HELM.Domains" table="orderlines" lazy="false">
    <id name="Orderid" column="OrderID" type="System.Int32">
      <generator class="assigned"/>
    </id>
    --<<...snipped out irrelevant fields...>>--
    <property column="OrderLineID" name="OrderLineid" type="System.Int32" not-null="true"/>

   [b]<many-to-one name="OrderId" column="Orderid" class="HELM.Domains.Orders" />[/b]

  </class>
</hibernate-mapping>


You always need a relationship on both sides to enable automatic saving.

Regards
Klaus


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 10, 2006 2:20 pm 
Beginner
Beginner

Joined: Mon Oct 02, 2006 6:46 pm
Posts: 32
that was the issue, thank you for your help.


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.