Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

EclipseLink/Development/JPA2.0/uni-directional onetomany mapping

Uni-directional OneToMany with Target Table

JPA 2.0 Root | Enhancement Request

Issue Summary

The JPA 1.0 specification only allows for uni-direction OneToMany mapping that uses a Join Table but the JPA 2.0 specification will require support for a uni-direction OneToMany mapping where no Join Table is involved. The defaulting rules for a Uni-directional OneToMany have not changed and defaulted uni-directional OneToMany mappings will still default to using a Join Table but if the developer provides @JoinColumn or @JoinColumns on the uni-directional OneToMany mapping then a target table mapping must be used.

See JPA 2.0 ED 9.1.33 for details

General Solution

A new mapping UnidirectionalOneToManyMapping will be defined. It will handle adding and removal of target objects following the pattern established in ManyToManyMapping. The new mapping will not be private owned by default.

Requirements

  1. JPA.
    1. @OneToMany resolved as the following mapping in the core:
      1. if has mappedBy - OneToMany on the source; ManyToOne on the target (already implemented in Eclipselink 1.0);
      2. if doesn't have mappedBy
        1. if provided together with @JoinColumn or @JoinColumns - UnidirectionalManyToMany on the source (new)
          1. No mapping for foreign key on the target.
          2. Support for all @OneToMany functionality (cascading, joins, etc).
          3. Addition or removal of the target from the source should trigger target's version change.
        2. otherwise - ManyToMany on the source (relational table could be provided in @JoinTable, otherwise generated) (already implemented in Eclipselink 1.0).
  2. Core.
    1. A new version of one to many mapping that doesn't require the target foreign key to be mapped by the target descriptor.
    2. All EclipseLink featurues (unless explicitlly exempted) should work with the new mapping: cascading, joins, historical sessions, batch reading, etc.
    3. Addition or removal of the target from the source should trigger target's version change.

Details

The new class UnidirectionalOneToManyMapping will be derived from OneToManyMapping overriding only the methods that deal with adding and removing of the traget objects. It will follow the pattern of ManyToManyMapping

Implementation sequence

  1. First the new class UnidirectionalOneToMany weill be implemented in Core along with the simple tests (add / remove target objects).
    1. That should include all the features that used by JPA (Optimistic locking: target version change on pk change).
    2. Because all the reading methods are inherited without change from OneToMany the advanced testing of reading could be postponed or skipped altogether.
  2. Add JPA support - annotation and orm xml processing.
    1. Add JPA tests.
  3. Add support to the remaining Eclipselink features (not currently used by JPA) historical sessions, etc.

Work Required

  1. Develop model for testing including joining queries
    approx 1 day
  2. Develop a mapping that supports uni-directional OneToMany mapping in EclipseLink that does not use Join Table
    approx 7 days
  3. Process @JoinColumn annotation and xml on a OneToMany mapping and test
    approx 2 days

Back to the top