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.
source
share