sql server - NHibernate session.flush() fails but makes changes -


We have a SQL Server database table that contains User ID, some numeric values, e.g. Balance, and a version column.

We have multiple threads which update the value column of this table in parallel, each in its own transaction and session (we are using the session-per-thread model). Since we all want logical transactions, each thread follows:

  1. Load the existing line (map for one type).
  2. Make changes to the value, based on the old value (for example 50 add).
  3. session.update (obj)
  4. session.flush () (Because we are optimistic, we want to make sure that we had the correct version value earlier
  5. If Step 4 (Flush) threw StaleStateException, refresh the object (with lockmode.read) and goto Step 1

We only make it count of a certain per logical transaction If we can not do this after X efforts, then we reject logical transactions.

Each such thread is time-consuming For example, to keep committed-driven I / O at manageable levels after 100 successful logical transactions, meaning - we have a single database transaction (per transaction), which is very low with many flush There is a logical change at least once.

What is the problem here, you ask? Ok, but we see changes in the failed logical objects. Specifically, if the value was 50, when we did step 1 ( First time) to go through A, and we tried to update it to 100 (but we failed because as another thread changed it to 70), then the value of 50 is that this line is obviously wrong. It is wrong.

What are we missing here?

Well, I do not have a ton of experience here, but one thing to remember is that if If there is an exception, you want to immediately withdraw the transaction and want to settle the session. Maybe your problem relates to the session that occurs in an inconsistent state?

Also, here is the call to update the update in your code. Since you loaded the object in that session, it is already being tracked by nhibernate.


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

jquery - SimpleModal Confirm fails to submit form -

php - Multiple Select with Explode: only returns the word "Array" -