The persist method of the EntityManager interface is not implemented according to the specification. If handed an already existing entity, it throws an instance of PersistenceException instead of EntityExistsException. The fact that the exception's cause is an instance of DuplicateEntityException does not help clients to determine the reason for the failure in a vendor-independent fashion. Changing this behavior will most likely not break existing clients, because they often catch instances of PersistenceException, which will also catch EntityExistsException instances. However, it will enable clients to detect the reason for the failure and thereby allow for better error reporting to the user. In fact, in case no transaction is running while this call fails, clients can also recover from the failure and queued actions can be committed afterwards.
Apache Maven 2.2.1 (r801777; 2009-08-06 21:16:01+0200)
Java version: 1.5.0_22
Java home: C:\Program Files\Java\jdk1.5.0_22\jre
Default locale: de_DE, platform encoding: Cp1252
OS name: "windows 7" version: "6.1" arch: "amd64" Family: "windows"
Replace DuplicateEntityException in the above description with NonUniqueObjectException, sorry for the confusion.
patch applied, thanks for the pull request.