0

In my EJB project deployed on WAS 6.1, when I try to call EntityManamger.merge(obj), I get this exception:

Exception data: <openjpa-1.0.4-SNAPSHOT-r420667:955062 nonfatal store error> org.apache.openjpa.persistence.EntityExistsException: Attempt to persist detached object "com.data.entity.SomeEntity@23aa23aa".  If this is a new instance, make sure any versino and/or auto-generated primary key fields are null/default when persisting.
FailedObject: com.bmo.ctp.data.entity.attribute.RoleResServiceAttribute@23aa23aa
    at org.apache.openjpa.kernel.BrokerImpl.persist(BrokerImpl.java:2368)
    at org.apache.openjpa.kernel.AttachStrategy.persist(AttachStrategy.java:94)
    at org.apache.openjpa.kernel.VersionAttachStrategy.attach(VersionAttachStrategy.java:95)
    at org.apache.openjpa.kernel.AttachManager.attach(AttachManager.java:241)
    at org.apache.openjpa.kernel.AttachStrategy.attachCollection(AttachStrategy.java:333)
    at org.apache.openjpa.kernel.AttachStrategy.replaceCollection(AttachStrategy.java:301)
    at org.apache.openjpa.kernel.AttachStrategy.attachField(AttachStrategy.java:220)
    at org.apache.openjpa.kernel.VersionAttachStrategy.attach(VersionAttachStrategy.java:157)
    at org.apache.openjpa.kernel.AttachManager.attach(AttachManager.java:241)
    at org.apache.openjpa.kernel.AttachManager.attach(AttachManager.java:101)
    at org.apache.openjpa.kernel.BrokerImpl.attach(BrokerImpl.java:3161)
    at org.apache.openjpa.kernel.DelegatingBroker.attach(DelegatingBroker.java:1142)
    at org.apache.openjpa.persistence.EntityManagerImpl.merge(EntityManagerImpl.java:665)
    at com.ibm.ws.jpa.management.JPAExEmInvocation.merge(JPAExEmInvocation.java:335)
    at com.ibm.ws.jpa.management.JPAEntityManager.merge(JPAEntityManager.java:123)

I do not have the source for JPAEntityManager.java; but I thought the EntityExistsException cannot be thrown by the merge() operation since merge will first do a check to see if entity exists. If not, insert it. If yes, update it. What is going wrong here?

Victor
  • 16,609
  • 71
  • 229
  • 409
  • You are correct that the merge method doesn't declare an EntityExistsException. I suspect something bad is happening with the OpenJPA runtime and it is incorrectly detecting that the Entity that you are trying to merge is new, rather than an update. Can you post snippets of your Id and Version attributes? Also, a little better description of the scenario would be nice. ie: Where did the Entity come from that you are merging? – Rick Mar 18 '12 at 13:37
  • Thank you for your reply. I will try to post more. – Victor Mar 19 '12 at 14:07

1 Answers1

0

Please check how your entitymanager checks the existence of an entity. Is it using Cache? or is it using a DB Query. This issue generally occurs, if the existence check is done through cache.

if you are using eclipselink JPA, this configuration is maintained in orm.xml

Thanks, Anand

Anand
  • 16