EclipseLink/DesignDocs/293925/MOXyExtensions/XmlInverseReferenceMapping

From Eclipsepedia

Jump to: navigation, search

XMLInverseReferenceMapping

Requirements

Provide support for XML inverse reference mapping configuration via XML metadata file.

The following should be supported:

  • Get/set method names
  • Mapped-by

XML Schema

Following is the proposed schema change required to support Xml inverse reference mappings:

<xs:element name="xml-inverse-reference" substitutionGroup="java-attribute">
    <xs:complexType>
        <xs:complexContent>
            <xs:extension base="java-attribute">
                <xs:all>
                    <xs:element ref="xml-access-methods" minOccurs="0" />
                </xs:all>
                <xs:attribute name="mapped-by" type="xs:string" />
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>
</xs:element>

Example

The follow demonstrates how an XML inverse reference mapping can be configured via XML metadata:

org.example.Employee.java

package org.example;
 
import javax.xml.bind.annotation.XmlElement;
 
public class Employee {
    @XmlElement
    public String name;
 
    @XmlElement
    public Address address;
}

org.example.Address.java

package org.example;
 
import org.eclipse.persistence.oxm.annotations.XmlInverseReference;
 
public class Address {
    @XmlElement
    public String street;
 
    @XmlElement
    public String city;
 
    @XmlInverseReference(mappedBy="address")
    public Employee owningEmployee;
}

org\example\employee-oxm.xml

<?xml version="1.0" encoding="US-ASCII"?>
<xml-bindings xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm" 
              xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <java-types>
        <java-type name="org.example.Employee">
            <java-attributes>
                <xml-element java-attribute="name" />
                <xml-element java-attribute="address" />
            </java-attributes>
        </java-type>
        <java-type name="org.example.Address">
            <java-attributes>
                <xml-element java-attribute="street" />
                <xml-element java-attribute="city" />
                <xml-inverse-reference java-attribute="owningEmployee" mapped-by="address" />
            </java-attributes>
        </java-type>
    </java-types>
</xml-bindings>

Open Issues

This section lists the open issues that are still pending that must be decided prior to fully implementing this project's requirements.

Issue# Owner Description/Notes

Decisions

This section lists decisions made. These are intended to document the resolution of open issues or constraints added to the project that are important.

Issue# Description/Notes Decision