@Version checking when reading entity?

View: New views
2 Messages — Rating Filter:   Alert me  

@Version checking when reading entity?

by cl333r :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Folks, is it worth checking the @Version field before trying to update an in-memory entity from the database table?
If so, can you please share a link or example how this is usually done?

Using JPA, EclipseLink & MySQL 5.

Re: @Version checking when reading entity?

by James Sutherland :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Probably not worth it, as optimistic locking is normally optimistic.

If you really wanted to, you could do a select on the version and check it ("Select o.version from MyObject o where o.id = :id"), or even just refresh the object.

cl333r wrote:
Folks, is it worth checking the @Version field before trying to update an in-memory entity from the database table?
If so, can you please share a link or example how this is usually done?

Using JPA, EclipseLink & MySQL 5.