I'm new to mybatis, I want to know does mybatis provide some method such as refreshAndLock like toplink? How can I make sure that the record I select can't be modified by other thread.
Does myBatis provide some method such as refreshAndLock?
1.2k views Asked by mengying.ye At
2
There are 2 answers
0
On
As far as I know, Ibatis does not support any locking, not even optimistic, let alone pessimistic locking.
Most Java applications use optimistic locking only, may be you can give it a try. You can add optimistic locking to iBatis yourself, here it is explained how to do that with spring : optimistic-locking-on-ibatis
mybatis does not have such method. mybatis is too low level for this. You need to do that manually.
For pessimistic locking this would look like this:
<select id="refreshAndLock" resultType="YourType"> SELECT * FROM TableStoringYourType WHERE id = #{id} FOR UPDATE </select>