JDO
  1. JDO
  2. JDO-702

Support for specification of embedded inherited objects

    Details

      Description

      While JDO2+ allows specification of embedded objects stored with primary objects, it doesn't have any specific way of specifying the embedded object as being inherited and how you would persist it. In particular there is no way to define a discriminator (column) for the embedded object. If we have an example from the JDO spec, and if we have a subclass of Address as also persistable, then we need to specify the discriminator for "primaryAddress" field.

      <class name="Employee" table="EMP">
      ...
      <!-- field type is Address -->
      <field name="primaryAddress">
      <embedded null-indicator-column="PADDR_STREET">
      <discriminator column="PADDR_DISCRIM"/>
      <field name="street" column="PADDR_STREET"/>
      <field name="city" column="PADDR_CITY"/>
      <field name="state" column="PADDR_STATE"/>
      <field name="zip" column="PADDR_ZIPCODE"/>
      </embedded>
      </field>
      </class>

      So the XSD/DTD need updates to allow <discriminator> under <embedded>, the JDO Metadata API needs to allow this also, and the @Embedded annotation needs a "discriminator" attribute adding.

      1. JDO-702.patch
        3 kB
        Andy Jefferson
      2. JDO-702-test.patch
        31 kB
        Andy Jefferson

        Activity

        Hide
        Andy Jefferson added a comment -

        Patch that

        • adds DiscriminatorMetadata to EmbeddedMetadata
        • adds <discriminator> subelement to <embedded> in DTD/XSD
        • adds Discriminator member to @Embedded.
        Show
        Andy Jefferson added a comment - Patch that adds DiscriminatorMetadata to EmbeddedMetadata adds <discriminator> subelement to <embedded> in DTD/XSD adds Discriminator member to @Embedded.
        Hide
        Andy Jefferson added a comment -

        Improved patch that makes the Metadata API methods consistent with what is done in other classes for subcomponents

        Show
        Andy Jefferson added a comment - Improved patch that makes the Metadata API methods consistent with what is done in other classes for subcomponents
        Hide
        Andy Jefferson added a comment -

        and fix member name on @Embedded

        Show
        Andy Jefferson added a comment - and fix member name on @Embedded
        Hide
        Craig L Russell added a comment -

        Sounds good.

        Show
        Craig L Russell added a comment - Sounds good.
        Hide
        Craig L Russell added a comment -

        So all we need is a tck test case?

        I'll take care of the specification update.

        Show
        Craig L Russell added a comment - So all we need is a tck test case? I'll take care of the specification update.
        Hide
        Andy Jefferson added a comment -

        Sure, but what form does this testcase take? I was thinking of a simple subclass of Address, however a change to the company model seems to imply creating duplicated interfaces and implementations across various packages ... not just company, but also companyAnnotatedFC, companyAnnotated JPA, companyAnnotatedPC, companyAnnotatedPI etc. All I want is a subclass and a way of instantiating it (e.g CompanyFactory.newXXXAddress), without having to dup it many times. What is the minimum that this company model will accept ?

        Show
        Andy Jefferson added a comment - Sure, but what form does this testcase take? I was thinking of a simple subclass of Address, however a change to the company model seems to imply creating duplicated interfaces and implementations across various packages ... not just company, but also companyAnnotatedFC, companyAnnotated JPA, companyAnnotatedPC, companyAnnotatedPI etc. All I want is a subclass and a way of instantiating it (e.g CompanyFactory.newXXXAddress), without having to dup it many times. What is the minimum that this company model will accept ?
        Hide
        Craig L Russell added a comment -

        Not clear that we need to update the company model. A stand alone model for just this feature would work for me.

        The advantage of the company model is that there is a lot of infrastructure already written. And changing the Address classes/interfaces probably isn't best because the most common case for Address is embedded without subclasses. So probably another model is needed anyway. Or create another package outside the company model but use the company infrastructure (e.g. the completeness test).

        You also want to make sure that the query features (cast, relationships from embedded subtypes, projections of embedded types) work properly.

        Show
        Craig L Russell added a comment - Not clear that we need to update the company model. A stand alone model for just this feature would work for me. The advantage of the company model is that there is a lot of infrastructure already written. And changing the Address classes/interfaces probably isn't best because the most common case for Address is embedded without subclasses. So probably another model is needed anyway. Or create another package outside the company model but use the company infrastructure (e.g. the completeness test). You also want to make sure that the query features (cast, relationships from embedded subtypes, projections of embedded types) work properly.
        Hide
        Andy Jefferson added a comment -

        Patch includes new model with embedded inheritance and 4 tests; persistence of base embedded type, persistence of subclass embedded type, query (cast, instanceof) of base embedded type, query (cast, instanceof) of subclasses embedded type.

        Show
        Andy Jefferson added a comment - Patch includes new model with embedded inheritance and 4 tests; persistence of base embedded type, persistence of subclass embedded type, query (cast, instanceof) of base embedded type, query (cast, instanceof) of subclasses embedded type.
        Hide
        Andy Jefferson added a comment -

        Original patch to update EmbeddedMetaData, @Embedded and DTD/XSD is now applied to SVN trunk as revision r1232104

        Show
        Andy Jefferson added a comment - Original patch to update EmbeddedMetaData, @Embedded and DTD/XSD is now applied to SVN trunk as revision r1232104
        Hide
        Andy Jefferson added a comment -

        Patch for tests now applied to SVN trunk.

        Show
        Andy Jefferson added a comment - Patch for tests now applied to SVN trunk.
        Hide
        Craig L Russell added a comment -

        The specification update for this feature is brief. Chapter 18 under Embedded. Anything else needed?

        "The optional discriminator attribute specifies the column to be used as the discriminator for the embedded object. "

        Show
        Craig L Russell added a comment - The specification update for this feature is brief. Chapter 18 under Embedded. Anything else needed? "The optional discriminator attribute specifies the column to be used as the discriminator for the embedded object. "
        Hide
        Craig L Russell added a comment -

        A bit more descriptive for Chapter 18:

        The optional discriminator attribute specifies the column to be used as the discriminator for the embedded object. This column would be used in case the type of the embedded object has subclasses.

        And in 15.4:

        Mapping embedded objects supports inheritance . In this case, the discriminator attribute would specify the discriminator strategy.

        svn 1402590

        Show
        Craig L Russell added a comment - A bit more descriptive for Chapter 18: The optional discriminator attribute specifies the column to be used as the discriminator for the embedded object. This column would be used in case the type of the embedded object has subclasses. And in 15.4: Mapping embedded objects supports inheritance . In this case, the discriminator attribute would specify the discriminator strategy. svn 1402590

          People

          • Assignee:
            Craig L Russell
            Reporter:
            Andy Jefferson
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development