[
https://issues.apache.org/jira/browse/OPENJPA-2405?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13695758#comment-13695758
]
Jody Grassel edited comment on OPENJPA-2405 at 6/28/13 8:37 PM:
----------------------------------------------------------------
I propose the attached fix for this issue, which allows the reporter's sample
test to pass.
Basically the idea is simple: check if the object to be merged (toAttach) has a
StateManager associated with it. If it does and that StateManager is a
StateManagerImpl (which DetachedStateManager is not a descendent of) then grab
its broker reference.
If this broker reference is different than the broker being used to perform the
merge() operation, then set isManagedByAnotherPCtx=true.
Then modify isNew to the following logic:
boolean isNew = !broker.isDetached(pc) && !isManagedByAnotherPCtx;
Basically, if toAttach is not detached and it is not managed by another
persistence context, then it is to be considered a new object. If toAttach is
not detached (because pc.isDetached() is not broker context aware) but if it is
managed by some other broker,t hen it should NOT be considered a new object.
(Disclaimer: have not run the full junit suite yet, will do so after posting
this.)
was (Author: fyrewyld):
I propose the attached fix for this issue, which allows the reporter's
sample test to pass.
Basically the idea is simple: check if the object to be merged (toAttach) has a
StateManager associated with it. If it does and that StateManager is a
StateManagerImpl (which DetachedStateManager is not a descendent of) then grab
its broker reference.
If this broker reference is different than the broker being used to perform the
merge() operation, then set isManagedByAnotherPCtx=true.
Then modify isNew to the following logic:
boolean isNew = !broker.isDetached(pc) && !isManagedByAnotherPCtx;
Basically, if toAttach is not detached and it is not managed by another
persistence context, then it is NOT to be considered a new object.
(Disclaimer: have not run the full junit suite yet, will do so after posting
this.)
> EntityManager.merge does not work for entity that is managed by another
> EntityManager
> -------------------------------------------------------------------------------------
>
> Key: OPENJPA-2405
> URL: https://issues.apache.org/jira/browse/OPENJPA-2405
> Project: OpenJPA
> Issue Type: Bug
> Affects Versions: 2.2.3
> Reporter: Arne Limburg
> Attachments: openjpa-2405-2.1.x.patch, OPENJPA-2405.patch
>
>
> EntityManager.merge does not work for entity that is managed by another
> EntityManager. Instead of updating that entity OpenJPA tries to persist the
> entity a second time
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira