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

Generated ID starting with 0 can cause unexpected results

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 2.2.0
    • None
    • kernel
    • None
    • any DB that allows a generated id to start with 0. And an entity that maps that generated id to an int instead of an Integer

    Description

      Several DB's allow a generated id column to start with 0.

      For instance, DB2 allows "GENERATED ALWAYS AS IDENTITY (START WITH 0)...."

      When this is used, the very first object will have an id of 0. When entities are first created, the user usually won't fill in the corresponding id field (since it will be generated by the DB when the entity is put in the DB), so it defaults to 0. The entity manager then uses this 0 and sees that an entity already exists and will update the old entity in stead of creating a new one.

      This is not a large issue, because a user could simply specify "START WITH 1" as a very simple workaround or they could use an Integer instead of an int, but it would be nice to fix so that new users don't hit this problem.

      Attachments

        1. GeneratedIDStartsWith0.ZIP
          4 kB
          Barrett Jay Reed

        Issue Links

          Activity

            People

              Unassigned Unassigned
              bjreed Barrett Jay Reed
              Votes:
              3 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated: