title: org.apache.openjpa.persistence.EntityExistsException in jpa
body: <p>I have a JTA transcation which manages transaction of 2 databases A and B.Now inside jta transcation i have a method that  return a entity from db A.How i want to set some different values to some primary key (primary key is composit primary key) and then persist the entity as a new record.But am getting following exception:</p>
  
  <pre><code>                                 &lt;openjpa-1.2.2-SNAPSHOT-r422266:778978M-OPENJPA-975 nonfatal store error&gt; org.apache.openjpa.persistence.EntityExistsException: Attempt to persist detached object "xyz.abc@616f991c".  If this is a new instance, make sure any version and/or auto-generated primary key fields are null/default when persisting.
  FailedObject: xyz.abc-
      at org.apache.openjpa.kernel.BrokerImpl.persist(BrokerImpl.java:2421)
      at org.apache.openjpa.kernel.BrokerImpl.persist(BrokerImpl.java:2280)
      at org.apache.openjpa.kernel.DelegatingBroker.persist(DelegatingBroker.java:1021)
      at org.apache.openjpa.persistence.EntityManagerImpl.persist(EntityManagerImpl.java:645)
      at com.ibm.ws.jpa.management.JPAExEmInvocation.persist(JPAExEmInvocation.java:339)
      at com.ibm.ws.jpa.management.JPAEntityManager.persist(JPAEntityManager.java:133)
      at com.ibm.cloud.bss.db.data.controller.CostrateManager.createCostrate(CostrateManager.java:94)
      at com.ibm.cloud.bss.omt.catalog.impl.BundleManager.saveSubcomponentInECW(BundleManager.java:409)
      at com.ibm.cloud.bss.omt.catalog.impl.BundleManager.createBundle(BundleManager.java:274)
      at com.ibm.cloud.omt.OfferingManagementSOAPBindingImpl.createBundle(OfferingManagementSOAPBindingImpl.java:222)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:45)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
      at java.lang.reflect.Method.invoke(Method.java:599)
      at org.apache.axis2.jaxws.server.dispatcher.JavaDispatcher.invokeTargetOperation(JavaDispatcher.java:81)
      at org.apache.axis2.jaxws.server.dispatcher.JavaBeanDispatcher.invoke(JavaBeanDispatcher.java:98)
      at org.apache.axis2.jaxws.server.EndpointController.invoke(EndpointController.java:109)
      at org.apache.axis2.jaxws.server.JAXWSMessageReceiver.receive(JAXWSMessageReceiver.java:159)
      at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:188)
      at org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:275)
      at com.ibm.ws.websvcs.transport.http.WASAxis2Servlet.doPost(WASAxis2Servlet.java:1389)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:738)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:831) 
  </code></pre>
  
  <p>I searched on net and i fold this post similar to myne:
  <a href="http://openjpa.208410.n2.nabble.com/persisting-an-entity-and-JPA-behaviour-with-referenced-entities-td210469.html" rel="nofollow">http://openjpa.208410.n2.nabble.com/persisting-an-entity-and-JPA-behaviour-with-referenced-entities-td210469.html</a></p>