Help! NHibernate: SQL update or deletion failed (row not found)
Hi, I keep getting:
SQL update or deletion failed (row not found)
When I try to delete a record... I can't figure out what's wrong with my code:
Code:
sess = connManager.GetWarehouseNHibernateSession(True)
trx = sess.BeginTransaction()
zInv = sess.Load(GetType(warehouse.to.zInventory), inv_id, LockMode.None)
If Not zInv Is Nothing Then
If PerformAdditionalChecks(...) Then
trx.Rollback()
Return DataManager.ERROR_ZINVENTORY_DELETE_OUTSTANDING_SWATCHES
End If
Else
trx.Rollback()
Return DataManager.ERROR_ZINVENTORY_DELETE_ITEMNOTFOUND
End If
'STEP 2. Remove from Database
sess.Delete(zInv)
sess.Flush() [b]'Every time I flush I get ADOException??[/b]
trx.Commit()
I still can't solved this... But, is this why?
MS SQL Server with JSQLConnect driver throws exception with delete()
Hibernate 2.0.1 propagates an exception from Session.flush() following Session.delete(Object):
net.sf.hibernate.HibernateException: SQL update or deletion failed (row not found)
at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:25)
NonBatchingBatcher.addToBatch expects PreparedStatement.executeUpdate() to return 1, but it returns 0 in this case, even though it has deleted 1 row from the database.
I solved this problem by appending "/lastUpdateCount=true" to the JDBC url for JSQLConnect. This makes the JDBC driver behave as Hibernate expects. Without this property, it seems the driver returned the number of rows updated by a trigger that was executed as a side-effect of the requested change. See http://www.j-netdirect.com/JSQLConnect/TechnicalReference.html#ConnectSettings for more information.
Reference: http://www.google.ca/url?sa=t&ct=res&cd=5&url=http%3A//www.hibernate.org/74.html%3Fcmd%3Dcomphist%26histnode%3D436&ei=sgEUQ8DbI7WaiAKl4rHODg
So, does it has to do with lastUpdateCount? How do I configure this though?
I dont see how lastUpdateCount can be configured for NHibernate...
Reference: http://www.google.ca/url?sa=t&ct=res&cd=1&url=http%3A//nhibernate.sourceforge.net/nh-docs/en/html/chunk/ch02.html&ei=CwYUQ4j8HZqkiAKuhfHGDg
Here're the mapping files... for your information:
http://www.codeguru.com/forum/showthread.php?p=1222298#post1222298
Or
http://nhibernate.sourceforge.net/forum/viewtopic.php?p=2186#2186
Thanks in advance!