I have an entity which I deleted, and then try to reinsert. I get an error of "NHibernate.StaleStateException: Unexpected row count: 0; expected: 1.".
I can see through the sql output that instead of reinserting the cascaded PurchaseOrderItem it is trying to update them. The relevant Mappings and classes can be found at the same pastebin I posted about my other issue earlier http://pastebin.com/m385a6457. I posted this issue separately but I believe it may very well be related to my other issue. I managed to get the delete to work by sharing the same session with the all the methods in the test class but then I get this error trying to reinsert. It seems to me that this is either a bug or more likely something is wrong with my mappings or session creation. Not sure where I went wrong here. The SQL being output is: NHibernate: DELETE FROM PurchaseOrderItem WHERE Id = @p0;@p0 = 59 NHibernate: DELETE FROM PurchaseOrderItem WHERE Id = @p0;@p0 = 60 NHibernate: DELETE FROM PurchaseOrder WHERE Id = @p0;@p0 = 54 NHibernate: SELECT purchaseor0_.Id as Id1_0_, purchaseor0_.DateAdded as DateAdded1_0_, purchaseor0_.CompanyId as CompanyId1_0_, purchaseor0_.AddedBy as AddedBy1_0_ FROM PurchaseOrder purchaseor0_ WHERE purchaseor0_....@p0;@p0 = 54 NHibernate: INSERT INTO PurchaseOrder (DateAdded, CompanyId, AddedBy) VALUES (@p0, @p1, @p2); select SCOPE_IDENTITY();@p0 = 1/28/2010 12:01:48 PM, @p1 = 107, @p2 = 697d8d17-4160-4c1a-a808-75c02fa6139e NHibernate: UPDATE PurchaseOrderItem SET Quantity = @p0, Price = @p1, ProductId = @p2, PurchaseOrderId = @p3 WHERE Id = @p4;@p0 = 3, @p1 = 101.35, @p2 = 4956, @p3 = 55, @p4 = 59 The offending code is: Public Sub Can_Remove_PurchaseOrder() Dim po As PurchaseOrder = _TestPurchaseOrders(0) Dim repo As IPurchaseOrderRepository = New PurchaseOrderRepository(_Session) repo.Remove(po) Dim savedPo As PurchaseOrder Using Transaction As ITransaction = _Session.BeginTransaction() savedPo = _Session.Get(Of PurchaseOrder)(po.Id) Transaction.Commit() End Using Assert.IsNull(savedPo) 'Replace po Using Transaction As ITransaction = _Session.BeginTransaction() _Session.Save(po) Transaction.Commit() End Using End Sub -- 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.
