简体   繁体   中英

lock select for update but don't lock regular select

I am implementing a system in which I differentiate between SELECT ... and SELECT ... FOR UPDATE .

The regular SELECT ... is used to read entities, which are allowed to be in an 'incorrect' state (incorrect = might be updated moments after)

The SELECT ... FOR UPDATE is ALWAYS used to read an object with goal to edit it, so it should return the correct state of the object.

Now I'm trying to do the following: whenever an object is read by the SELECT ... FOR UPDATE statement, lock other SELECT ... FOR UPDATE queries on the same object. However, regular SELECT ... should still work.

Is there any way of doing this by using just predefined locks? I looked at database isolation levels, but I don't think they are a part of my problem.

I'm using java, hibernate and an sql database.

Select for update doesn't locks in MySQL. Its worked in Oracle, Postgres, MS SQL.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM