OpenJPA
  1. OpenJPA
  2. OPENJPA-1260

Wrong sequence is generated for custom native sequence generator from getIdGenerator.

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.3.0, 2.0.0
    • Fix Version/s: 1.1.1, 1.3.0, 2.0.0-M3
    • Component/s: sql
    • Labels:
      None
    • Patch Info:
      Patch Available
    1. OPENJPA-1260-trunk.patch
      7 kB
      Ravi P Palacherla
    2. OPENJPA-1260-trunk.patch
      7 kB
      Ravi P Palacherla
    3. openJPA-1260_1.1.x.patch
      9 kB
      Ravi P Palacherla

      Activity

      Hide
      Ravi P Palacherla added a comment -

      OpenJPAEntityManager.getIdGenerator.next() fails to generate correct sequence number when class uses native sequence geneartor.

      The cause of the issue is OpenJPAEntityManager.getIdGenerator.next() goes against the default sequence openjpa_sequence rather than the defined sequence.
      So the SQL on openjpaentitymanager.getIdGenerator.next() is
      SELECT SEQUENCE_VALUE FROM OPENJPA_SEQUENCE_TABLE WHERE ID = ? FOR UPDATE
      even though a native sequence generator is defined.

      @Id
      @GeneratedValue(strategy=GenerationType.SEQUENCE,
      generator="entityE2_seq_gen_name")
      @SequenceGenerator(name="entityE2_seq_gen_name",
      sequenceName="entityE2_seq_gen")
      private int id;

      Show
      Ravi P Palacherla added a comment - OpenJPAEntityManager.getIdGenerator.next() fails to generate correct sequence number when class uses native sequence geneartor. The cause of the issue is OpenJPAEntityManager.getIdGenerator.next() goes against the default sequence openjpa_sequence rather than the defined sequence. So the SQL on openjpaentitymanager.getIdGenerator.next() is SELECT SEQUENCE_VALUE FROM OPENJPA_SEQUENCE_TABLE WHERE ID = ? FOR UPDATE even though a native sequence generator is defined. @Id @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="entityE2_seq_gen_name") @SequenceGenerator(name="entityE2_seq_gen_name", sequenceName="entityE2_seq_gen") private int id;
      Hide
      Ravi P Palacherla added a comment -

      Testcase & Fix.

      Show
      Ravi P Palacherla added a comment - Testcase & Fix.
      Hide
      Michael Dick added a comment -

      Hi Ravi,

      The patch looks good but I'd recommend moving the testcase to a different package, org.apache.openjpa.persistence.jdbc.sequence or just org.apache.openjpa.persistence.sequence. The testcase isn't using delimited identifiers so it'd be a bit misleading to put it in that package.

      Otherwise the patch looks great.

      Show
      Michael Dick added a comment - Hi Ravi, The patch looks good but I'd recommend moving the testcase to a different package, org.apache.openjpa.persistence.jdbc.sequence or just org.apache.openjpa.persistence.sequence. The testcase isn't using delimited identifiers so it'd be a bit misleading to put it in that package. Otherwise the patch looks great.
      Hide
      Ravi P Palacherla added a comment -

      Uploaded patch with new package and class name.

      Show
      Ravi P Palacherla added a comment - Uploaded patch with new package and class name.
      Hide
      Donald Woods added a comment -

      Modified patch committed to trunk by Kevin Sutter in r813597 and back ported to 1.3.0 by Donald Woods in r813868.

      Show
      Donald Woods added a comment - Modified patch committed to trunk by Kevin Sutter in r813597 and back ported to 1.3.0 by Donald Woods in r813868.
      Hide
      Donald Woods added a comment -

      Mike, please reopen if you want to apply this to 1.2.x or 1.0.x.

      Show
      Donald Woods added a comment - Mike, please reopen if you want to apply this to 1.2.x or 1.0.x.
      Hide
      David Ezzio added a comment -

      Applied Ravi's 1.1.x patch at revision 890402

      Show
      David Ezzio added a comment - Applied Ravi's 1.1.x patch at revision 890402

        People

        • Assignee:
          Michael Dick
          Reporter:
          Ravi P Palacherla
        • Votes:
          0 Vote for this issue
          Watchers:
          0 Start watching this issue

          Dates

          • Created:
            Updated:
            Resolved:

            Development