java - Is it possible to isolate db table from read operations in transaction? -


i'm writing java app(spring data/hibernate/jpa), should work mysql db. have simple task, should atomic: 1. retrieve first item database 2. bind item current user(update item set user_id=current_user_id id=id)

i've put 500ms pause between these 2 steps test against concurrency , run in transaction. transaction exists, @ least rollbacks if throw exception in code. atomicity doesn't work want to, 500ms pause following situation:

  1. user1 starts transaction
  2. user1 retrieves first item - item1
  3. user2 starts transaction
  4. user2 retrieves first item - item1
  5. user1 updates item1
  6. user1 commits transaction
  7. user2 updates item1
  8. user2 commits transaction

is there way isolate table user2's read/write queries while user1 in transaction? should db level transaction allow 2 instances of app on different servers.

you shoiuld either use select update lock or introduce versions on hibernate level (read optimistic lock here).


Comments

Popular posts from this blog

Process 'command 'F:\android-sdk\build-tools\21.1.2\aapt.exe'' finished with non-zero exit value 1 -

apache - setting document root in antoher partition on ubuntu -

java - Updating to mongo 3.0 -