2 Replies Latest reply on Dec 18, 2006 6:57 PM by vk101

    What causes EntityExistsException?

      What causes an EntityExistsException to be thrown from EntityManager's persist method?

      Is it anytime the database has a row with the same primary key? Or is it anytime the database has a row with any unique key being the same? Or do all fields have to be the same? Does it check existing entities in the persistence context that haven't necessarily yet been flushed to the database?

      Could somebody please explain what it takes for two entities (or rows in the database) to be seen as the same so as to throw an EntityExistsException (i.e. if they have some fields being the same, but not all)?

        • 1. Re: What causes EntityExistsException?
          epbernard

          if the entity is already persistent in the PC, calling persist() will raise EPE

          • 2. Re: What causes EntityExistsException?

            What qualifies as being "already persistent"?

            Does that mean an entity whose equals() test returns true, or does it look at the @Entity definition at the Id and/or @Column(unique=true) fields only?

            Also, does it drill down to the actual database layer at insertion time for tables with unique constraints but no corresponding annotation defined on the entity? Or does that come back as a different kind of error?

            I haven't seen this documented anywhere, so I'm wondering...

            Thanks.