OpenJPA
  1. OpenJPA
  2. OPENJPA-1066

Generated ID starting with 0 can cause unexpected results

    Details

    • Type: Improvement Improvement
    • Status: Open
    • Priority: Minor Minor
    • Resolution: Unresolved
    • Affects Version/s: 2.2.0
    • Fix Version/s: None
    • Component/s: kernel
    • Labels:
      None
    • Environment:
      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.

        Issue Links

          Activity

          B.J. Reed created issue -
          B.J. Reed made changes -
          Field Original Value New Value
          Attachment GeneratedIDStartsWith0.ZIP [ 12407343 ]
          Donald Woods made changes -
          Fix Version/s 2.0.0 [ 12314019 ]
          Fix Version/s 2.0.0-M2 [ 12313483 ]
          Michael Dick made changes -
          Fix Version/s 2.0.1 [ 12314532 ]
          Fix Version/s 2.0.0 [ 12314019 ]
          Rick Curtis made changes -
          Link This issue blocks OPENJPA-1665 [ OPENJPA-1665 ]
          Rick Curtis made changes -
          Link This issue blocks OPENJPA-1665 [ OPENJPA-1665 ]
          Rick Curtis made changes -
          Link This issue is related to OPENJPA-1665 [ OPENJPA-1665 ]
          Donald Woods made changes -
          Fix Version/s 2.0.2 [ 12315257 ]
          Fix Version/s 2.1.0 [ 12314542 ]
          Fix Version/s 2.0.1 [ 12314532 ]
          Michael Dick made changes -
          Affects Version/s 2.2.0 [ 12315910 ]
          Affects Version/s 2.0.0-M2 [ 12313483 ]
          Michael Dick made changes -
          Fix Version/s 2.1.0 [ 12314542 ]
          Fix Version/s 2.0.2 [ 12315257 ]
          Vermeulen made changes -
          Comment [ Don't know if this helps, but I found a similar bug on EclipseLink (https://bugs.eclipse.org/bugs/show_bug.cgi?id=297198) they solved it by using something like "GENERATED BY DEFAULT AS IDENTITY (START WITH 1...". ]

            People

            • Assignee:
              Unassigned
              Reporter:
              B.J. Reed
            • Votes:
              2 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:

                Development