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

Difference between revisions of "EclipseLink/Development/JPA2.0/association-override-join-table"

(Annotation)
(XML - Embeddable override)
Line 67: Line 67:
 
<code><pre>
 
<code><pre>
  
 +
<mapped-superclass class="RatedBeerConsumer" access="FIELD">
 +
  <attributes>
 +
    <embedded name="accredidation">
 +
      <association-override name="witnesses">
 +
        <join-table name="XML_EBC_ACCREDIDATION_WITNESS">
 +
          <join-column name="XML_EBC_ID" referenced-column-name="ID"/>
 +
            <inverse-join-column name="XML_WITNESS_ID" referenced-column-name="ID"/>
 +
        </join-table>
 +
      </association-override>
 +
      <association-override name="officials">
 +
        <join-column name="FK_EBC_ID"/>
 +
      </association-override>
 +
    </embedded>
 +
 +
    ...
 +
  </attributes>
 +
</mapped-superclass>
 
</pre></code>
 
</pre></code>
  

Revision as of 10:44, 2 June 2009

Association Override Join Table support

JPA 2.0 Root | Enhancement Request

Issue Summary

JPA 2.0 specification introduced support for relational mappings such as 1-M, M-M etc on embeddable class. With that comes the option to specify an association override to apply to those mappings within the embeddable, namely those mappings that use a join table. Note an association override can also be specified at the entity level and applied to a mapping from a mapper superclass. This is existing functionality, however with the introduction of the join table element within the association override in JPA 2.0, this support needs to be implemented.

At the same time, changes will be made to support association override join columns on a uni-directional one to many from an embeddable class. Note, that support (although not explicitely supported from the spec in JPA 1.0) for association override join columns to 1-1 and 1-M mappings from an embeddable class was already implemented and tested.

Association overrides are described in detail in section 11.1.2 of the specification.

General Solution

For the most part, the solution for this will mainly be in the metadata processing. However, to support an association override join table from an embeddable class will require some changes to core code, namely to AggregateObjectMapping.

Examples

Annotation

@Embeddable
public class Accredidation {
    @OneToMany(cascade={PERSIST, MERGE})
    List<Official> officials;
    
    @ManyToMany(cascade={PERSIST, MERGE})
    List<Witness> witnesses;

    ...
}

@MappedSuperclass
public class RatedBeerConsumer {

    @Embedded
    @AssociationOverrides({
        @AssociationOverride(name="witnesses", joinTable=@JoinTable(name="EBC_ACCREDIDATION_WITNESS",
            joinColumns=@JoinColumn(name="EBC_ID", referencedColumnName="ID"),
            inverseJoinColumns=@JoinColumn(name="WITNESS_ID", referencedColumnName="ID"))),
        @AssociationOverride(name="officials", joinColumns=@JoinColumn(name="FK_EBC_ID"))
    })
    private Accredidation accredidation;

    ...
}

@Entity
@AssociationOverrides({
    @AssociationOverride(name="accredidation.officials", joinColumns=@JoinColumn(name="FK_NBC_ID")),
    @AssociationOverride(name="accredidation.witnesses", joinTable=@JoinTable(name="NBC_ACCREDITATION_WITNESS",
        joinColumns=@JoinColumn(name="NBC_ID", referencedColumnName="ID"),
        inverseJoinColumns=@JoinColumn(name="WITNESSID", referencedColumnName="ID")))
})
public class NoviceBeerConsumer extends RatedBeerConsumer {
   ...
}

@Entity
// No association overrides, will use those defined on the embedded mapping from the mapped superclass.
public class ExpertBeerConsumer extends RatedBeerConsumer {
   ...
}

XML - Embeddable override


<mapped-superclass class="RatedBeerConsumer" access="FIELD">
  <attributes>
    <embedded name="accredidation">
      <association-override name="witnesses">
        <join-table name="XML_EBC_ACCREDIDATION_WITNESS">
          <join-column name="XML_EBC_ID" referenced-column-name="ID"/>
            <inverse-join-column name="XML_WITNESS_ID" referenced-column-name="ID"/>
        </join-table>
      </association-override>
      <association-override name="officials">
        <join-column name="FK_EBC_ID"/>
      </association-override>
    </embedded>

    ...
  </attributes>
</mapped-superclass>

Work Required

  1. Develop model for testing
    approx 5 day
  2. Update Processing
    approx 10 days

Back to the top