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
|