Hi,
I have a system that deals with two classes. They form a parent-children relationship. The children are created first and later I want to add them to a new parent. The mapping files look like:
child:
<set name="_items"
table="Item"
lazy="true"
inverse="true"
cascade="update">
<key column="BatchId"></key>
<one-to-many class="Batch"></one-to-many>
</set>
parent:
<many-to-one
name="_batch"
class="Batch"
cascade="none"
outer-join="auto"
insert="true"
update="true"
column="BatchId"
not-null="false" />
Testing code looks like:
Batch batch = new Batch();
batch.Number = "2_string";
batch.NumberOfBills = 2;
batch.Total = 50;
Bill bill = (Bill)session.Load(typeof(Bill), 3);
bill.Batch = this;
batch.Bills.Add(bill);
session.Save(batch);
When i creat a parent and add existing children to it then save it, only the parent is persisted to database. The "BatchId" in the child record never get updated.
The generated sql only show one insert.
NHibernate: INSERT INTO CareBatch (NumberOfBills, Total, Number) VALUES (@p0, @p1, @p2); select SCOPE_IDENTITY()
@p0 = '2'
@p1 = '50'
@p2 = '2_string'
what did i do worng?
Thank a lot.
Hongze
|