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:
- user1 starts transaction
- user1 retrieves first item - item1
- user2 starts transaction
- user2 retrieves first item - item1
- user1 updates item1
- user1 commits transaction
- user2 updates item1
- 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
Post a Comment