update and return data in spring data JPA
<p>For concurrency purpose, I have got a requirement to update the state of a column of the database to USED while selecting from AVAILABLE pool.</p>

<p>I was thinking to try <code>@Modifying</code>, and <code>@Query</code>(query to update the state based on the where clause)</p>

<p>It is all fine, but this is an update query and so it doesn't return the updated data.</p>

<p>So, is it possible in spring data, to update and return a row, so that whoever read the row first can use it exclusively.</p>

<p>My update query is something like <code>UPDATE MyObject o SET o.state = 'USED' WHERE o.id = (select min(id) from MyObject a where a.state='AVAILABLE')</code>, so basically the lowest available id will be marked used. There is a option of locking, but these requires exceptional handling and if exception occur for another thread, then try again, which is not approved in my scenario</p>