In my application I'm having an issue with saving BOs that have a parent/child relationship on a transaction. To simplify things for testing I created two BOs, ParentBO1 and ChildBO1 and defined a parent/child relationship between them. I dropped the BOs on to a standard SF form and excluded them from the form save, delete, undo etc. form events. I'm not using any stored procedures and have concurrency checking as OptimisticAllFields.
On the form I have the following save method:
Private Sub SaveAllOnTransaction()
Try
BusinessLayer.TransactionBegin("", Data.IsolationLevel.ReadCommitted)
'-- Save objects
Me.ParentBO1.Save(True)
Me.ChildBO1.Save(True)
'-- Commit Transaction
BusinessLayer.TransactionCommit("")
Catch ex As Exception
'-- Rollback transaction
BusinessLayer.TransactionRollback("")
'-- Show inner exception
MessageBox.Show(ex.InnerException.Message)
End Try
End Sub
The test form simply loads the Parent and Child BOs, places the Parent in edit mode and displays a list view of child objects that may be selected for editing or new child objects may be added using a ChildFormDialog.
If I simply edit the ParentBO and save, everything works okay. If I leave the ParentBO alone (Although it is marked as IsDirty since it was placed in editing mode) and modify or add a child record and save, everything works okay. However if I modify both the Parent and Child BOs and try to save, the program hangs and eventually an exception is thrown saying "Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.".
Modifying the save method as follows eliminates the error.
'-- Save objects
If Me.ChildBO1.IsDirty Then
Me.ChildBO1.Save(True)
ElseIf Me.ParentBO1.IsDirty Then
Me.ParentBO1.Save(True)
End If
It would appear that the framework is trying to save the ParentBO twice, if there are actual changes to the ParentBO and ChildBO causing an error when saving the Parent a second time under a transaction. I know that the framework is designed to save the Parent when a child is saved. but it is not recognizing that the child has already saved the parent when Save(true) is called on the parent. This is only an issue when objects with a parent/child relationship are saved on a transaction. I'm using v1.61
-Larry