[ https://issues.apache.org/jira/browse/OPENJPA-2405?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13693671#comment-13693671 ]
Arne Limburg commented on OPENJPA-2405: --------------------------------------- 1. So you agree with me that it is a BUG that OpenJPA tries to INSERT the entity and throws an exception due to the duplicate key? 2. Yes, I have read that chapter of the spec, too. And I come to the conclusion, that the only way to interpret it, is that managed entities of the SAME persistence context are meant. Your way of reading the spec simply does not work. Think of the following situation: a. Entity A is loaded by EntityManager X. Entity A has a Cascade.ALL relation to Entity B. b. Entity B is newly created and assigned to A c. Entity A is merged to EntityManager Y. Now Entity B would be managed by EntityManager Y due to the cascading behavior you cited. In addition Entity B would be managed by EntityManager X due to 3.2.4 Spec 3.24 ===================== The semantics of the flush operation, applied to an entity X are as follows: - If X is a managed entity, it is synchronized to the database. - For all entities Y referenced by a relationship from X, if the relationship to Y has been annotated with the cascade element value cascade=PERSIST or cascade=ALL, the persist operation is applied to Y. ===================== How do you think OpenJPA should behave in such situation? Should Entity B be managed by two persistence contexts? Btw. Any other persistence provider returns a managed copy of Entity A in such situation, no matter if A is managed by another persistence context or detached. And this is the expected behavior, I guess. > 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