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

        Issue Links

          Activity

            People

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

              Dates

              • Created:
                Updated:
                Resolved:

                Development