OpenJPA
  1. OpenJPA
  2. OPENJPA-466

Primary key constraint violated using (Oracle) sequence to generate ID in multithreaded app

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Blocker Blocker
    • Resolution: Fixed
    • Affects Version/s: 1.0.0, 1.0.1, 1.1.0, 1.2.0
    • Fix Version/s: 1.0.4, 1.2.2, 1.3.0, 2.0.0-M3
    • Component/s: None
    • Labels:
      None
    • Environment:
      OpenJPA 1.0.0 (also tried 1.0.1 and 1.1.0-SNAPSHOT)
      Oracle XE 10g (JDBC driver 10.2.0.3.0)
      Windows XP Pro
    • Patch Info:
      Patch Available

      Description

      Here's how I annotate the ID:
      @Id
      @SequenceGenerator(name = "FooSeq", sequenceName = "seq_foo", allocationSize = 20)
      @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "FooSeq")
      private Long id;

      Here's how I create the (Oracle) sequence:
      CREATE SEQUENCE seq_foo START WITH 1 INCREMENT BY 1;

      I get a primary key unique constraint violated in a multithreaded app i.e. it doesn't happen in single-threaded!

      You can simply reproduce this error by either create blocking queue or blocking thread pool say size 5 to insert 10000+ object.

      1. OPENJPA-466.patch
        29 kB
        Tim McConnell
      2. OPENJPA-466.patch
        1 kB
        Milosz Tylenda
      3. volatile.patch
        0.6 kB
        Milosz Tylenda
      4. OPENJPA-466-SYNCRONIZED.patch
        0.7 kB
        Tim McConnell
      5. OPENJPA-466-1.0.x.patch
        30 kB
        B.J. Reed
      6. OPENJPA-466-1.2.x.patch
        30 kB
        B.J. Reed
      7. TestSequenceGenerationOnMT.java
        2 kB
        Pinaki Poddar
      8. GeneratedIdObject.java
        0.5 kB
        Pinaki Poddar

        Issue Links

          Activity

          Frank Le created issue -
          Tim McConnell made changes -
          Field Original Value New Value
          Assignee Tim McConnell [ mcconne ]
          Tim McConnell made changes -
          Status Open [ 1 ] In Progress [ 3 ]
          Tim McConnell made changes -
          Affects Version/s 1.2.0 [ 12313102 ]
          Affects Version/s 1.1.0 [ 12312344 ]
          Affects Version/s 1.0.1 [ 12312687 ]
          Tim McConnell made changes -
          Attachment OPENJPA-466.patch [ 12400305 ]
          Albert Lee made changes -
          Fix Version/s 2.0.0 [ 12313483 ]
          Tim McConnell made changes -
          Status In Progress [ 3 ] Resolved [ 5 ]
          Resolution Fixed [ 1 ]
          Tim McConnell made changes -
          Status Resolved [ 5 ] Closed [ 6 ]
          Milosz Tylenda made changes -
          Resolution Fixed [ 1 ]
          Status Closed [ 6 ] Reopened [ 4 ]
          Milosz Tylenda made changes -
          Assignee Tim McConnell [ mcconne ] Milosz Tylenda [ milosz ]
          Milosz Tylenda made changes -
          Attachment OPENJPA-466.patch [ 12406496 ]
          Milosz Tylenda made changes -
          Status Reopened [ 4 ] Resolved [ 5 ]
          Fix Version/s 1.3.0 [ 12313326 ]
          Resolution Fixed [ 1 ]
          Kevin Sutter made changes -
          Resolution Fixed [ 1 ]
          Status Resolved [ 5 ] Reopened [ 4 ]
          Tim McConnell made changes -
          Patch Info [Patch Available]
          Milosz Tylenda made changes -
          Attachment volatile.patch [ 12408717 ]
          Donald Woods made changes -
          Fix Version/s 2.0.0 [ 12314019 ]
          Fix Version/s 1.3.0 [ 12313326 ]
          Fix Version/s 2.0.0-M2 [ 12313483 ]
          Tim McConnell made changes -
          Attachment OPENJPA-466-SYNCRONIZED.patch [ 12413238 ]
          Tim McConnell made changes -
          Status Reopened [ 4 ] Resolved [ 5 ]
          Resolution Fixed [ 1 ]
          Donald Woods made changes -
          Resolution Fixed [ 1 ]
          Status Resolved [ 5 ] Reopened [ 4 ]
          Michael Dick made changes -
          Status Reopened [ 4 ] Resolved [ 5 ]
          Fix Version/s 1.3.0 [ 12313326 ]
          Resolution Fixed [ 1 ]
          Donald Woods made changes -
          Fix Version/s 2.0.0-M3 [ 12314148 ]
          Fix Version/s 2.0.0 [ 12314019 ]
          B.J. Reed made changes -
          Attachment OPENJPA-466-1.0.x.patch [ 12417527 ]
          Attachment OPENJPA-466-1.2.x.patch [ 12417528 ]
          Donald Woods made changes -
          Fix Version/s 1.0.4 [ 12313301 ]
          Fix Version/s 1.2.2 [ 12313681 ]
          Pinaki Poddar made changes -
          Resolution Fixed [ 1 ]
          Status Resolved [ 5 ] Reopened [ 4 ]
          Pinaki Poddar made changes -
          Attachment TestSequenceGenerationOnMT.java [ 12422576 ]
          Attachment GeneratedIdObject.java [ 12422577 ]
          Milosz Tylenda made changes -
          Status Reopened [ 4 ] Resolved [ 5 ]
          Resolution Fixed [ 1 ]
          Milosz Tylenda made changes -
          Link This issue is related to OPENJPA-1372 [ OPENJPA-1372 ]
          Donald Woods made changes -
          Status Resolved [ 5 ] Closed [ 6 ]

            People

            • Assignee:
              Milosz Tylenda
              Reporter:
              Frank Le
            • Votes:
              5 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development