|Multi-threaded overwrites [message #1001948]
||Thu, 17 January 2013 10:43
| Justin Stewart
Registered: September 2012
Hi, all - |
I'm new to EclipseLink, so this may be easy.
I'm using version 2.4.1 in Virgo 3.5.
So here's the problem. I have entity classes A and B, which have a one-to-one relationship with each other. Here's the order of events that reproduces the problem:
1. Thread 1 reads instance A(1) of type A.
2. Thread 2 reads instance B(1) of type B that is linked to A(1) by the one-to-one relationship.
3. Thread 1 changes A(1) and merges/flushes it to the database.
4. Thread 2 changes B(1) and merges/flushes it to the database. In the process of this write, the change that was made to A(1) by thread 1 is overwritten in the database - and the old contents of A(1) are written. This is because in the one-to-one definition of B to A, I had cascade/cascade-all. So a write to B(1) cascaded to a write of A(1). And the instance of A(1) held by thread 2 was not affected by the changes made by thread 1. Removing the cascade fixed this problem.
My concern is the bigger picture where I won't have this workaround.
In an environment like Virgo, multiple threads is the norm. If each thread may operate on different entity instances representing the same row in the database - and their actions are not coordinated or cooperative, there is not much hope of maintaining data integrity.
Is there something I am missing in terms of usage or best practices?
Granted, the eclipselink.cache.shared.default property has been set to false in this project for some reason - and this may be the cause. If these entity instances were proxies to a single cached object, it seems that changes to any entity would be reflected across all proxy instances.
Any thoughts? Thanks.
Powered by FUDForum
. Page generated in 0.01523 seconds