[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[eclipselink-users] IndirectSet/IndirectList relationship may cause transaction/session mix up
|
Hi,
I am seeing a strange EclipseLink (2.3.2) behavior:
Imagine an entity class A which refers to an entity class B via
OneToMany(cascade=PERSIST) relationship which itself refers to entity
class C via ManyToOne(cascade=PERSIST) relationship.
Furthermore imagine the following steps:
1. find() entity B with entity manager 1 (which contains references to
at least one entity C)
2. Detach this entity from entity manager 1 (optional step)
3. create a new instance of A
4. set a reference from A to the detached B
5. Persist A on entity manager 2
When tracing through the operations which EclipseLink does on
persist(), the resolving of the relationship B->C which is done by
IndirectSet.buildDelegate() seems to re-use the Session/UnitOfWork from
entity manager 1!
In the best case this will lead to some exceptions (e.g. the connection
from entity manager 1 has already been closed before), but in the worst
this will silently lead to strange dirty read/data inconsistency
situations.
At least with the optional step 2, the detachment, I would never expect
that such an entity is still silently referencing and using the entity
manager on which it was previously attached.
But even without the detachment this would be very questionable.
I thought that (at least detached) entities can be considered as simple
beans and do not have any restrictions regarding share/re-usage.
Is this behavior expected?
(Related:
http://stackoverflow.com/questions/11398527/jpa-entity-sharing-among-different-entity-managers
)
Thank you and best regards,
Patric