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: unsaved transient instance - multiple new objects
PostPosted: Fri Jun 20, 2008 7:20 am 
Newbie

Joined: Mon Oct 15, 2007 9:59 am
Posts: 6
Hi,

I've got a problem with "object references an unsaved transient instance".

I'm using:
NHibernate 1.2.0 GA
SQL Server 2005 and identity fields for all my keys
C# 2.0

example ORM Snips (all ORM files are the same as this)

<class name="Order" table="Allocation.[Order]" lazy="false">
<id name="_id" column="Id" type="Int32" unsaved-value="0">
<generator class="identity" />
</id>
<set name="_orderItems" table="Allocation.OrderItem" lazy="true" inverse="true" cascade="all-delete-orphan" >
<key column="OrderId" />
<one-to-many class="OrderItem" />
</set>

...
</class>

<class name="OrderItem" table="Allocation.OrderItem" lazy="false">
<id name="_id" column="Id" type="Int32" unsaved-value="0">
<generator class="identity" />
</id>

<many-to-one name="_order" column="OrderId" class="Order" not-null="true" />

..
</class>


I'm creating several new objects that are all related with a single root (i.e. An Order is the root, this has order items, which have accounting entries. An order has one or more Delivery Allocations, which has Allocation Items etc.)

When I create create a single new order on it's own and save it - SaveOrUpdateCopy(order) - the code I have works fine. All related objects are correctly persisted to the database.

When I create two or more orders and save them I get the "unsaved transient instance" exception. It's as if NHibernate is getting confused between the fact there are two seperate unsaved object graphs for Order, despite the fact they are two distinct orders in the object model.

I'm really stuck - the fact the code works for a single order suggests its nothing I'm doing wrong.

Any ideas?
Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 23, 2008 4:45 pm 
Expert
Expert

Joined: Fri Oct 28, 2005 5:38 pm
Posts: 390
Location: Cedarburg, WI
My experience is that there are long-reported but unfixed bugs when saving multiple transient instances, particularly when two transient instances need to reference each other.

Our solution so far has been to save and flush each transient instance immediately in the transaction. For transient instances that need to reference each other (e.g. parent and child), one must be saved and flushed first, before the next can reference the first and be saved & flushed.


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.