The lifecycle of entity instances are managed within the persistence context using <? > <persistence xmlns=" xmlns:xsi=" xsi:schema Location=" version="2.0"> <persistence-unit name="com.concretepage"> <description> JPA Demo</description> <provider>org.
Hibernate Persistence</provider> <class>com.concretepage.entity. Farmer</class> <properties> <property name="hibernate.dialect" value="org.hibernate.dialect. My SQLDialect"/> <property name="hibernate.hbm2ddl.auto" value="update"/> <property name="javax.driver" value="com.
The second invocation will just be ignored, although the persist operation might be cascaded to any associations of the entity that were added since the first invocation.
How can I get the Entity Manager.merge() function to produce true merge SQL statements where only the field values that have actually been modified are ...==================== merge() is for "detached" entity only. Per Spec: ==================== 220.127.116.11 Merging Detached Entity State The merge operation allows for the propagation of state from detached entities onto persistent entities managed by the entity manager. 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.The semantics of the merge operation applied to an entity X are as follows: ........ And I come to the conclusion, that the only way to interpret it, is that managed entities of the SAME persistence context are meant. However, the child relationship is still processed if proper cascade is specified. 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. ================================= In the original test case, A (managed by em, not detached) is merged to em2 and there is no managed A in em2. In addition Entity B would be managed by Entity Manager X due to 3.2.4 Spec 3.24 ===================== The semantics of the flush operation, applied to an entity X are as follows: Btw. So you agree with me that it is a BUG that Open JPA tries to INSERT the entity and throws an exception due to the duplicate key? The behavior is undefined if the same Java instance is made managed in more than one persistence context.