JPA optimistic handling of the lock version - should the version value be ported to the client side or?

I am wondering how to handle the optimistic locking property in an entity class using JPA (basic requirements) from server to client and vice versa.

Here is the script.

  • From the request of the browser user, send a request to the server, requesting individual user information for editing.

  • The server processes the request and returns the result to the browser. Server code looks something like this:

    EntityManager em = EmProvider.getInstance (). getEntityManagerFactory (). createEntityManager ();

    User u = (User) em.find (User.class, myUserId);

    return u; // answer back to the browser

Here's my confusion - the User table has a column "version"for optimistic locking.

This means that the version field value is also sent back to the client, even if the client (me or anyone) has never used it . The version field must be used on the server side.

Is it right to send the version number to the client? Because otherwise, I cannot figure out how to check the version number if the user clicks the "UPDATE" button on the modified data web page.

Please let me know if you need more clarification.

+3
source share
1 answer

Yes, you will send the version number to the client so that it can later send it back to the server (along with the changes that it wants to make for the entity), which can use it to check for conflicting updates.

, ? ( , ). , "" , .

, , ( -) .

, . , , , , . ( " " , Stackoverflow).

+5

Source: https://habr.com/ru/post/1783534/


All Articles