views:

53

answers:

1

I have to write a simple demo for amount withdrawl from a joint Bank amount .Andy and Jen holds a joint bank account with number 123 . Suppose they have 100$ in their account .Jen and Andy are operating their account at the same time and both are trying to withdraw 90$ at the time being .My transaction Isolation is set to read-committed and both are able to withdraw money leaving the balance to -(minus)80$ although I have constraint that balance should never be less than 0.

I am using hibernate .Is versioning only way to solve this problem or I should go for another Isolation level ?

A: 

I'm tempted to say that optimistic locking is indeed the way to go (and this is what I would do instead of changing the isolation level, concurrent accesses on the same record sounds like an exceptional situtation).

Pascal Thivent
Concurrent access is a critical thing to consider especialy in a banking app. It is NOT an exceptional situation.
HLGEM
@HLGEM Maybe I didn't express myself correctly but could you please show me where I wrote to ignore concurrent accesses? I suggested to use **optimistic** locking which is a way to deal with concurrency and is suitable if concurrent accesses on a same record are unlikely events, hence the **optimistic** in the name (optimistic locking may not work well with highly concurrent applications). The particular scenario of the question sounds like an exceptional event, and optimistic locking will work fine. If you understand what optimistic locking is, you should maybe reconsider your vote
Pascal Thivent