Uploaded image for project: 'OpenJPA'
  1. OpenJPA
  2. OPENJPA-466

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

VotersWatch issueWatchersLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Blocker
    • Resolution: Fixed
    • 1.0.0, 1.0.1, 1.1.0, 1.2.0
    • 1.0.4, 1.2.2, 1.3.0, 2.0.0-M3
    • None
    • None
    • 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 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.

      Attachments

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

        Issue Links

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            milosz Milosz Tylenda
            frankca Frank Le
            Votes:
            5 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment