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

NULL in columns part of an @IdClass composite key leads to "disappearing" (null) returned objects

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.2.1, 2.0.0-M3
    • 1.2.2, 1.3.0, 2.0.0-beta
    • jdbc, kernel
    • None

    Description

      As discussed on http://openjpa.markmail.org/search/?q=#query:list%3Aorg.apache.openjpa.users+page:1+mid:yua5kf7vd5m7wrnw+state:results, there is a bug in OpenJPA iff ... "any @Id field of a composite key mapped via an @IdClass identity is NULL" (enough keywords to allow future searching? .

      The attached test case provides running code illustrating this with two simple entities and a failing JUnit.

      While relational database do NOT appear to allow NULL value for columns which are part of a PRIMARY KEY CONSTRAINT, this kind of situation and mapping can (and in our case has!) occurred when mapping to legacy schemas with tables where a certain number / subset of columns are in fact the "logical" identifying set, without there being a physical PK constraint (nothing says you HAVE to have a physical PK). – Both JPA Spec and OpenJPA doc make no statement if this is supposed to work or not work, they say nothing about this (as far as I could see; I checked before filing this; and nobody on the list made any statements re. this). It would be interesting to know if and how other JPA implementations handle this.

      Assuming this is a small internal implementation bug and not a conceptual / design issue (note it's NOT the @IdClass instance that is null, it's only some fields within an Id, with others being available; and uniqueness of the combination guaranteed by data in DB of course!), it would be great if this could be make to work as one would naturally expect. (Or, at the very least, OpenJPA should fail and issue a clear error message, instead of just returning null; fix much better though.)

      Attachments

        1. openJPA_NullId.zip
          9 kB
          Michael Vorburger

        Activity

          People

            ppoddar@apache.org Pinaki Poddar
            vorburger Michael Vorburger
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: