I am using OpenJPA and I have a lock problem. I already understand what OptimisticLockException is and when it was thrown.
But how can I handle it?
Below * you can find a small paragraph on optimistic blocking exceptions.
In short, how can I completely disable the lock manager?
In my persistent.xml, I have the following xml code, but it does not work. Why?
... <properties> <property name="openjpa.LockManager" value="none" /> </properties> ...
* According to wikibooks about Java Persistent:
Optimistic Block Exception Handling
Unfortunately, programmers can often be too smart for their own good. The first problem that arises when using optimistic locking is what to do when an OptimisticLockException is thrown. A typical neighborhood programmer response is to automatically handle the exception. They simply create a new transaction, update the object to reset their version and combine the data back into the object and re-commit it. Is the Presto problem resolved, or is it?
This actually damages the entire blocking point. If this is what you want, you can also use a lock . Unfortunately, OptimisticLockException rarely needs to be handled automatically, and you really need to bother the user about this problem. You must report the conflict to the user and either say "your sorry, but the conflict of changes has occurred and they will have to redo their work", or at best, update the object and present the user with the current data and the data that they sent, and help them combine them, if necessary.
Some automated merge tools will compare two conflicting versions of the data, and if none of the individual fields conflict, the data will simply be automatically merged without user assistance. This is what most software version control systems do. Unfortunately, the user, as a rule, can better solve when something is a conflict than the program, simply because two versions of the .java file did not change the same line of code, does not mean that there was no conflict, the first user could remove the method that another user added the link method, and several other possible problems that cause the normal nightly build to fail so often.