alesj wrote:
Optimistic locking - @Version annotation.
Where do you want to use the same EM in different threads?
My application accesses managed entities from multiple threads. There's a sort of pipeline through which managed objects are passed. Worker threads in the pipeline are responsible for taking incoming objects in certain statuses, processing them and passing them on to the next worker (by updating the item statuses).
Should every thread have their own EntityManagers? How would i ensure an entity is not managed by more than one EntityManager at a given time in this case?
Some data related to managed entities is stored in the file system so before processing file system data the thread needs to ensure exclusive access to the entity. These modifications can't be undone right now, so the thread can't roll back the changes if there's an OptimisticLockException.