Does myBatis provide some method such as refreshAndLock?

1.2k Views Asked by At

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.

2

There are 2 best solutions below

0
Roman-Stop RU aggression in UA On BEST ANSWER

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>

0
Stefan Isele - prefabware.com 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