Hello,
I have this typical parent/child relationship. I want to delete/update
the child collection without explicitly call session.delete(child)

Parent mapping:
    <bag name="OrderTransactions" inverse="true" access="property"
cascade="all-delete-orphan">
      <key column="`OrderId`"/>
      <one-to-many class="OrderTransaction"/>
    </bag>

Child mapping:
<many-to-one name="OrderHeader" column="`OrderId`"
class="OrderHeader" access="property"  not-null="true"/>

        [Test]
        public void CanUpdateOrderTransaction()
        {
                var customerOrder = _orderModel.GetOrderById(new
Guid("1f384088-f199-4c93-878a-42d4eb0ac615"));
                var menuItem = _menuModel.GetMenuItemByMenuNo("1051");

                customerOrder.ClearTransactions();

                customerOrder.AddTransaction(new OrderTransaction()
                {
                    MenuItem = menuItem,
                    Quantity = 1,
                    UnitPrice = 3.4f
                });

                _orderModel.SaveCustomerOrder(customerOrder);

                customerOrder = _orderModel.GetOrderById(new
Guid("1f384088-f199-4c93-878a-42d4eb0ac615"));

                Assert.IsNotNull(customerOrder);
                Assert.AreEqual(1,
customerOrder.OrderTransactions.Count);
 
Assert.IsTrue(customerOrder.OrderTransactions[0].MenuItem.Equals(menuItem));
        }

The test fails with the message:
*** Failures ***
Execute
NHibernate.PropertyValueException: not-null property references a null
or transient
valueXenon.XenonPOS.DomainModel.Entities.OrderTransaction.OrderHeader
EntityName: Xenon.XenonPOS.DomainModel.Entities.OrderTransaction
PropertyName: OrderHeader

The problem is, when in child mapping not-null = "true" the test fails
but if it is set to false the test passes. I need to be able to set
not null property true because of the consistency of the database and
get the test pass as well. This is my first Nhibernate project. I
tried my level best to google the solution of the problem before
asking you guys and this far i have reached.  Any help will be greatly
appreciated.

-- 
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