I just ran into an interesting situation today. We would start a session and transaction. Part of this transaction involved creating and modifying a Library. Eventually, the transaction would get rolled back. and the Library removed from the database.
Immediately after that, we began a new transaction to create a new user. When we committed the transaction with the user, we received StaleStateExceptions.
It turns out that what was happening was that when we rolled back the Library transaction, the Library update commands were still queued up in the batcher and were not removed. The next time flush was executed (on the User commit), the batched update statements were being run on a Library id that was taken out of the database during the previous rollback.
Now I realize that the easy fix for all of this is to simply flush the session before the rollback. However, I was wondering if the batcher and session were intentionally created this way. Leaving the commands in the batcher after the transaction is rolled back seems like leaving some cleanup undone. And making systems flush commands that could simply be thrown out seems like a waste of cycles.
If someone has looked at this before and it is too difficult to change, I completely understand the "Just call flush" response. But as a relative newbie, I was a little supprised when ending transactions one way flushed the session and ending them another didn't. Or is there a reason to leave the commands in the session that I'm just not aware of?
Thanks
_________________ Chuck
Not in the face! Not in the face!
|