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

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -