jason.hill wrote:
Hi,
I was hoping that there was some way to lock the objects in the child collection when they are read from the DB, do the reshuffle, save them and then release the locks. Another user trying to do the same function would then be in a holding pattern until the first transaction has finished.
Jason, this is actually what was being referred to above. You can use locks if you want. But now you have to think about what is going to take place. There are a lot of different scenarios that can occur when dealing with concurrency. Think about the case where you issue a lock during update (the default SQL Server (assuming you are using Sql Server) behavior is to create exclusive update locks) and the other connections trying to read those records or other connections trying to write to those records will wait until that operation is complete.
When this happens the other user will be in a holding pattern until that update is complete, but once that update is complete their operation can complete successfully. So picture a case where user1 updates, and then user2 updates basically at the same time. The updates for user1 take place while user2 has his or her operations blocked by the lock user1 created. Once user1 releases the locks the update from user2 runs. This seems to be exactly what you are looking for. The only thing is using the version NHibernate will tell you that the update user2 is trying to perform is being performed on a stale object and is therefore unsafe.
So to me it looks like you are getting the results you desired, just maybe not for the exact reasons you expected.
If you wanted to you could also lock with a higher transaction isolation level at the start when the objects are first loaded preventing another user from even loading those objects until the fist process is done, so then their operation would be in a holding pattern until the read->write makes the full cycle.
These options are available, but they are really more database concepts than NHibernate concepts.