Hi,
I have this problem to solve where I have an entity that has these mapped properties (note that this is a really simplified version of my entity):
Code:
RequestEntity
boolean isOverridden
String otherField
In thread 1, when a new RequestEntity is created and inserted in the table, it also executes a JPQL UPDATE statement that sets the isOverridden property of other existing RequestEntity rows in the table.
In thread 2 (or another process), the RequestEntity instances are used and updated as well. This other thread does not care about the isOverridden property at all, but it must eventually save new values in the otherField property.
If both thread run at the same time, I have situations where the second thread overrides the isOverriden value that thread 1 updated with the one that it loaded before the update (which is different).
What is the best solution to this kind of problem? Both threads should be able to live together without waiting on each other to finish its job (i.e., there should be no lock and no stale exception should occur).
Ideally, the thread 2 should just save the RequestEntity without setting the isOverridden field, but that only seems possible if the update in thread 2 uses a JPQL UPDATE query that does not modify that property.
Is this a classical problem that has a classical solution?
--
Mel T