org.apache.openjpa.persistence.PersistenceException: The statement was aborted because it would have caused a duplicate key value in a unique or primary key constraint or unique index identified by 'SQL071203035857400' defined on 'MESSAGE'. {prepstmnt 28409161 INSERT INTO Message (message, created, id) VALUES (?, ?, ?) [params=(String) Hello Persistence!, (Timestamp) 2007-12-03 15:59:24.663, (long) 1196715564663]} [code=20000, state=23505] FailedObject: hellojpa.Message@89e2f1

Apache's JIRA Issue Tracker | Gul Onural | 9 years ago
  1. 0

    OpenJPA doesn't throw standard JPA exceptions in the case of failure to persist or commit. For example, the JPA spec states that the EntityExistsException is thrown by the persistence provider when EntityManager.persist(Object) is called and the entity already exists. However, the OpenJPA never raises the EntityExistsException, instead raises RollbackException. In order to produce the issue, just take the hellojpa example comes with the OpenJPA distro. and modify Message.java to make variable message an ID (original Message class uses timestamp as ID, just change the ID to be message variable for the purpose of reproducing the issue explained here) : @Id private String message; Then run the hellojpa after this very simple modification, twice. Second execution fails because of duplicate key. The stack trace is captured below and notice that there is no EntityExistsException in the stack trace at all. Because of this, the caller of the jpa objects cannot differenciate EntityExistsException from any other exception and for example the GUI cleints cannot display meaningful error code to reflect exactly what happend. Here is the stack trace : Buildfile: D:\apache-openjpa-1.0.0\examples\hellojpa\build.xml pre-compile: compile: run: [java] 3063 hellojpa TRACE [main] openjpa.jdbc.SQL - <t 26760685, conn 3238031> executing prepstmnt 28409161 INSERT INTO Message (message, created, id) VALUES (?, ?, ?) [params=(String) Hello Persistence!, (Timestamp) 2007-12-03 15:59:24.663, (long) 1196715564663] [java] 3157 hellojpa TRACE [main] openjpa.jdbc.SQL - <t 26760685, conn 3238031> [94 ms] spent [java] Exception in thread "main" <openjpa-1.0.0-r420667:568756 fatal store error> org.apache.openjpa.persistence.RollbackException: The transaction has been rolled back. See the nested exceptions for details on the errors that occurred. [java] at org.apache.openjpa.persistence.EntityManagerImpl.commit(EntityManagerImpl.java:419) [java] at hellojpa.Main.main(Main.java:53) [java] Caused by: <openjpa-1.0.0-r420667:568756 fatal general error> org.apache.openjpa.persistence.PersistenceException: The transaction has been rolled back. See the nested exceptions for details on the errors that occurred. [java] at org.apache.openjpa.kernel.BrokerImpl.newFlushException(BrokerImpl.java:2099) [java] at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:1946) [java] at org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java:1844) [java] at org.apache.openjpa.kernel.BrokerImpl.beforeCompletion(BrokerImpl.java:1762) [java] at org.apache.openjpa.kernel.LocalManagedRuntime.commit(LocalManagedRuntime.java:81) [java] at org.apache.openjpa.kernel.BrokerImpl.commit(BrokerImpl.java:1292) [java] at org.apache.openjpa.kernel.DelegatingBroker.commit(DelegatingBroker.java:861) [java] at org.apache.openjpa.persistence.EntityManagerImpl.commit(EntityManagerImpl.java:408) [java] ... 1 more [java] Caused by: <openjpa-1.0.0-r420667:568756 nonfatal general error> org.apache.openjpa.persistence.PersistenceException: The statement was aborted because it would have caused a duplicate key value in a unique or primary key constraint or unique index identified by 'SQL071203035857400' defined on 'MESSAGE'. {prepstmnt 28409161 INSERT INTO Message (message, created, id) VALUES (?, ?, ?) [params=(String) Hello Persistence!, (Timestamp) 2007-12-03 15:59:24.663, (long) 1196715564663]} [code=20000, state=23505] [java] FailedObject: hellojpa.Message@89e2f1 [java] at org.apache.openjpa.jdbc.sql.DBDictionary.newStoreException(DBDictionary.java:3849) [java] at org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:97) [java] at org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:67) [java] at org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flushInternal(PreparedStatementManagerImpl.java:108) [java] at org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flush(PreparedStatementManagerImpl.java:73) [java] at org.apache.openjpa.jdbc.kernel.ConstraintUpdateManager.flush(ConstraintUpdateManager.java:543) [java] at org.apache.openjpa.jdbc.kernel.ConstraintUpdateManager.flush(ConstraintUpdateManager.java:105) [java] at org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(AbstractUpdateManager.java:89) [java] at org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(AbstractUpdateManager.java:72) [java] at org.apache.openjpa.jdbc.kernel.JDBCStoreManager.flush(JDBCStoreManager.java:514) [java] at org.apache.openjpa.kernel.DelegatingStoreManager.flush(DelegatingStoreManager.java:130) [java] ... 8 more [java] Caused by: org.apache.openjpa.lib.jdbc.ReportingSQLException: The statement was aborted because it would have caused a duplicate key value in a unique or primary key constraint or unique index identified by 'SQL071203035857400' defined on 'MESSAGE'. {prepstmnt 28409161 INSERT INTO Message (message, created, id) VALUES (?, ?, ?) [params=(String) Hello Persistence!, (Timestamp) 2007-12-03 15:59:24.663, (long) 1196715564663]} [code=20000, state=23505] [java] at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.wrap(LoggingConnectionDecorator.java:192) [java] at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.access$800(LoggingConnectionDecorator.java:57) [java] at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator$LoggingConnection$LoggingPreparedStatement.executeUpdate(LoggingConnectionDecorator.java:858) [java] at org.apache.openjpa.lib.jdbc.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:269) [java] at org.apache.openjpa.jdbc.kernel.JDBCStoreManager$CancelPreparedStatement.executeUpdate(JDBCStoreManager.java:1363) [java] at org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flushInternal(PreparedStatementManagerImpl.java:97) [java] ... 15 more BUILD FAILED D:\apache-openjpa-1.0.0\examples\build.xml:84: Java returned: 1 Total time: 6 seconds

    Apache's JIRA Issue Tracker | 9 years ago | Gul Onural
    org.apache.openjpa.persistence.PersistenceException: The statement was aborted because it would have caused a duplicate key value in a unique or primary key constraint or unique index identified by 'SQL071203035857400' defined on 'MESSAGE'. {prepstmnt 28409161 INSERT INTO Message (message, created, id) VALUES (?, ?, ?) [params=(String) Hello Persistence!, (Timestamp) 2007-12-03 15:59:24.663, (long) 1196715564663]} [code=20000, state=23505] FailedObject: hellojpa.Message@89e2f1
  2. 0

    Wrong SQL update query generated on merge

    Stack Overflow | 3 years ago | Oleg_Andreych
    org.apache.openjpa.persistence.PersistenceException: Неправильный синтаксис около ключевого слова "WHERE". {prepstmnt 1814850604 UPDATE COMPANY_REF SET WHERE ID = ? [params=(int) 11751]} [code=156, state=S0001] FailedObject: ru.hostco.jpa.Company-11751
  3. 0

    JPA (openjpa), DB2, update, commit = Invalid cursor name?

    Stack Overflow | 4 years ago | Maxim Suponya
    org.apache.openjpa.persistence.PersistenceException: Invalid cursor name. FailedObject: prepstmnt 125018062 UPDATE CCHDEVT.TCC_PROPERTY SET COMMENTS = ?, LAST_UPDATED = ? WHERE PROPERTY_NAME = ? [org.apache.openjpa.jdbc.kernel.JDBCStoreManager$CancelPreparedStatement_]
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    HDP 2.0 Oozie Error: E0803 : E0803: IO error, E0603

    Stack Overflow | 3 years ago | jaksky
    org.apache.openjpa.persistence.PersistenceException: An SQL data change is not permitted for a read-only connection, user or database. {prepstmnt 2096695648 INSERT INTO WF_JOBS (id, app_name, app_path, conf, group_name, parent_id, run, user_name, bean_type, created_time, end_time, external_id, last_modified_time, log_token, proto_action_conf, sla_xml, start_time, status, wf_instance) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)} [code=20000, state=25502] FailedObject: org.apache.oozie.WorkflowJobBean@355319a8
  6. 0

    [GERONIMO-3907] Persistence Exception is not visible/lost for client. - ASF JIRA

    apache.org | 1 year ago
    org.apache.openjpa.persistence.PersistenceException: FEHLER: Einfügen oder Aktualisieren in Tabelle »person« verletzt Fremdschlüssel-Constraint »person_historie_fk_fkey« Detail: Schlüssel (historie_fk)=(27) ist nicht in Tabelle »historie« vorhanden. {prepstmnt 19422193 INSERT INTO vesuv.person (id, bemerkung, historie_fk, name, persontyp, phonetischer_diskriptor_name, vermoegensverzeichnis_fk, vorgaenger_version_fk) VALUES (?, ?, ?, ?, ?, ?, ?, ?) [params=(long) 7, (null) null, (long) 27, (String) , (int) 0, (String) , (long) 0, (null) null]} [code=0, state=23503] FailedObject: de.nrw.hagen.ggrz.bv.person.db.PersonPAO@124dc48

    2 unregistered visitors
    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. org.apache.openjpa.lib.jdbc.ReportingSQLException

      The statement was aborted because it would have caused a duplicate key value in a unique or primary key constraint or unique index identified by 'SQL071203035857400' defined on 'MESSAGE'. {prepstmnt 28409161 INSERT INTO Message (message, created, id) VALUES (?, ?, ?) [params=(String) Hello Persistence!, (Timestamp) 2007-12-03 15:59:24.663, (long) 1196715564663]} [code=20000, state=23505]

      at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.wrap()
    2. OpenJPA Aggregate Jar
      DelegatingStoreManager.flush
      1. org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.wrap(LoggingConnectionDecorator.java:192)
      2. org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.access$800(LoggingConnectionDecorator.java:57)
      3. org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator$LoggingConnection$LoggingPreparedStatement.executeUpdate(LoggingConnectionDecorator.java:858)
      4. org.apache.openjpa.lib.jdbc.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:269)
      5. org.apache.openjpa.jdbc.kernel.JDBCStoreManager$CancelPreparedStatement.executeUpdate(JDBCStoreManager.java:1363)
      6. org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flushInternal(PreparedStatementManagerImpl.java:97)
      7. org.apache.openjpa.jdbc.sql.DBDictionary.newStoreException(DBDictionary.java:3849)
      8. org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:97)
      9. org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:67)
      10. org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flushInternal(PreparedStatementManagerImpl.java:108)
      11. org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flush(PreparedStatementManagerImpl.java:73)
      12. org.apache.openjpa.jdbc.kernel.ConstraintUpdateManager.flush(ConstraintUpdateManager.java:543)
      13. org.apache.openjpa.jdbc.kernel.ConstraintUpdateManager.flush(ConstraintUpdateManager.java:105)
      14. org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(AbstractUpdateManager.java:89)
      15. org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(AbstractUpdateManager.java:72)
      16. org.apache.openjpa.jdbc.kernel.JDBCStoreManager.flush(JDBCStoreManager.java:514)
      17. org.apache.openjpa.kernel.DelegatingStoreManager.flush(DelegatingStoreManager.java:130)
      17 frames