Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to deal with locks (JPA)?
    primarykey
    data
    text
    <p>According to the <a href="http://en.wikibooks.org/wiki/Java_Persistence/Locking#Common_Locking_Mistakes.2C_Questions_and_Problems" rel="noreferrer">Java Persistent/Locking wikibooks</a>*, the best way to deal with locks is to report the Optimistic Lock Error/Exception to the user. </p> <p>The problem is that it's not scalable. Suppose that I have many users who are likely to cause a lock with the same action. The user does not care about the lock error message.</p> <p>In a nutshell :</p> <ul> <li>The best way is to disable all locks ?</li> <li>The best way is to report to the user the error lock message ? But the user must retry his action until it will work !</li> <li>The best way is to retry the transaction until there's no lock ?</li> </ul> <hr> <p>*</p> <blockquote> <p>Handling optimistic lock exceptions</p> <p>Unfortunately programmers can frequently be too clever for their own good. The first issue that comes up when using optimistic locking is what to do when an OptimisticLockException occurs. The typical response of the friendly neighborhood super programmer, is to automatically handle the exception. They will just create a new transaction, refresh the object to reset its version, and merge the data back into the object and re-commit it. Presto problem solved, or is it?</p> <p>This actually defeats the whole point of locking in the first place. If this is what you desire, you may as well use no locking. Unfortunately, the OptimisticLockException should rarely be automatically handled, and you really need to bother the user about the issue. You should report the conflict to the user, and either say "your sorry but an edit conflict occurred and they are going to have to redo their work", or in the best case, refresh the object and present the user with the current data and the data that they submitted and help them merge the two if appropriate.</p> <p>Some automated merge tools will compare the two conflicting versions of the data and if none of the individual fields conflict, then the data will just be automatically merged without the user's aid. This is what most software version control systems do. Unfortunately the user is typically better able to decide when something is a conflict than the program, just because two versions of the .java file did not change the same line of code does not mean there was no conflict, the first user could have deleted a method that the other user added a method to reference, and several other possible issues that cause the typically nightly build to break every so often. </p> </blockquote>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload