I did some experimenting tonight and found that given...

Customer
 has many Orders
   has many OrderedItems

If I...

var customer = new Customer();

var order = customer.CreateNewOrder();

var orderedItem = order.Add(product, QUANTITY_OF_ONE);

session.SaveOrUpdate(customer);

Then everyone will get an Id that I can immediately read right after
the SaveOrUpdate.  If instead I...


var customer = new Customer();

session.Save(customer);

var order = customer.CreateNewOrder();

var orderedItem = order.Add(product, QUANTITY_OF_ONE);

session.SaveOrUpdate(customer);

Then the customer and the order get an Id after the 2nd SaveOrUpdate.
I have to either session.Flush() OR session.Persist(orderedItem) if I
want the orderedItem to get an Id.

This matches up with what I noticed today at work but I'm not sure I
understand it from a consistency point of view.  Why does saving an
entity mean that the child entities no longer get an id immediately?

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.


Reply via email to