openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Albert Lee (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (OPENJPA-2405) EntityManager.merge does not work for entity that is managed by another EntityManager
Date Thu, 27 Jun 2013 15:37:20 GMT

    [ https://issues.apache.org/jira/browse/OPENJPA-2405?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13694802#comment-13694802
] 

Albert Lee commented on OPENJPA-2405:
-------------------------------------

I am just pointing out that merge() is meant for merging DETACHED entity into a persistence
context. If an entity is managed by the SAME persistence context, there is nothing to merge
since the state of X is already maintained, hence the merge operation is ignored. However,
the child relationship is still processed if proper cascade is specified.

The spec also spelled out the following;
=================================
3.2.8 Managed Instances
It is the responsibility of the application to insure that an instance is managed in only
a single persistence
context. The behavior is undefined if the same Java instance is made managed in more than
one
persistence context.
=================================

In the original test case,  A (managed by em, not detached) is merged to em2 and there is
no managed A in em2. Since A is marked managed and not managed in em2, OpenJPA creates a new
managed instance in em2 and eventually "INSERT" to the database. I am not saying this is the
right or wrong behavior but this use case is undefined.

If you wants to merge changed content in A to a different persistence context, you may have
to do:
- em.find(A);
- detach A from em2
- make changes to A
- em2.find(A);
- em2.merge(A);
- commit/flush em2

                
> 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.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

Mime
View raw message