OpenJPA
  1. OpenJPA
  2. OPENJPA-670

Discriminator column is missing from table when inheritance is used without annotation

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.2.0, 1.3.0
    • Fix Version/s: 1.2.0, 1.3.0
    • Component/s: jdbc
    • Labels:
      None

      Description

      According to the EJB 3.0 JPA spec (pp. 191, section 9.1.29):

      "If the Inheritance annotation is not specified or if no inheritance type is specified for an entity class
      hierarchy, the SINGLE_TABLE mapping strategy is used."

      I've found that if an entity inheritance hierarchy is specified without an explicit DiscriminatorColumn or Inheritance annotation, a single table will be used for mapping, but there will be no discriminator column in the table.

      pp. 191 - 192, section 9.1.30 of the spec reads:

      "For the SINGLE_TABLE mapping strategy, and typically also for the JOINED strategy, the persistence
      provider will use a type discriminator column."

      and

      "If the DiscriminatorColumn annotation is missing, and a discriminator column is required, the
      name of the discriminator column defaults to "DTYPE" and the discriminator type to STRING."

      Without a discriminator column a scenario such as:

      entity B extends entity A
      entity C extends entity A

      "select c from C" will return entities of type A, B, and C (which is a data integrity issue) because there is no way to distinguish between the entity types.

      The simple workaround is to specify an @Inheritance or @DiscriminatorColumn annotation on the root class, but OpenJPA should exhibit default behavior defined by the spec when these annotations are not specified.

      I have a patch and jUnits in the works and will post them shortly.

      1. openjpa-670.patch
        82 kB
        Jeremy Bauer

        Activity

        Donald Woods made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Michael Dick made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Assignee Jeremy Bauer [ techhusky ]
        Resolution Fixed [ 1 ]
        Michael Dick made changes -
        Fix Version/s 1.3.0 [ 12313326 ]
        Fix Version/s 1.2.0 [ 12313102 ]
        Jeremy Bauer made changes -
        Field Original Value New Value
        Attachment openjpa-670.patch [ 12387198 ]
        Jeremy Bauer created issue -

          People

          • Assignee:
            Jeremy Bauer
            Reporter:
            Jeremy Bauer
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development