-->
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: not-null property references a null or transient value
PostPosted: Mon Sep 12, 2005 6:02 pm 
When doing something like this:

Code:
(pseudo code obviously)
//customer is a customer loaded by NH from db with a list of associated orders

IList orders = customer.Orders

while (orders.hasnext)
{
   Order currentOrder = (Order)orders.Next();
  if(someClause)
  {
    //add new order
   Order newOrder = new Order();
   //I know this is wierd, but assume for a moment
  //that in my real code, I only have access to a single order,
  //and therefor have to navigate to its parent, in order to get a handle
  //to the full list of orders.
   currentOrder.Customer.Orders.Add(newOrder);
  }
}



I get the error not-null property references a null or transient value.

My mapping file for customer is:

Code:
      <id name="Id" column="Id" type="Int32" unsaved-value="0">
         <generator class="identity"/>
      </id>

      <bag name="Orders" table="Ordres" access="nosetter.camelcase" cascade="all" inverse="true" lazy="true" >
         <key column="customerId"/>
         <one-to-many class="foo.Order,foo"/>
      </bag>


and in Orders I have:

Code:
   <id name="Id" column="Id" type="Int32" unsaved-value="0">
         <generator class="identity"/>
      </id>
      <property column="Name" type="String" name="Name" not-null="true" length="32" />
      <many-to-one name="Customer" column="CustomerId" class="foo.Customer,foo" not-null="true"/>



Does anyone know what I am doing wrong. I have read some posts which seem to point in the direction of the unsaved-value, but as I understand it it seems as if I were doing things correctly... Not sure what I am doing wrong.


Top
  
 
 Post subject: Just to add...
PostPosted: Mon Sep 12, 2005 6:10 pm 
I've read that in bi-directional relationships I need to set the parent of the child manually. If this is what I am doing, what would I need to change in order to be able to simple add a child to the children of a parent and have it persist correctly.


Top
  
 
 Post subject:
PostPosted: Tue Sep 13, 2005 3:40 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Create a method Customer.AddOrder and use that to both add the order to the collection, and set order.Customer to this.


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.