Difference between revisions of "EclipseLink/UserGuide/MOXy/Relationships/Privately Owned/One-to-Many"

From Eclipsepedia

Jump to: navigation, search
m (New page: {{EclipseLink_UserGuide |info=y }} =One-to-Many Composite Collection Mapping Use XML composite collection mappings to represent one-to-many relationships. Composite collection XML mappings...)
 
m (Replacing page with 'See http://www.eclipse.org/eclipselink/documentation/2.4/moxy/privately_owned_relationships002.htm')
 
(39 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{EclipseLink_UserGuide
+
See http://www.eclipse.org/eclipselink/documentation/2.4/moxy/privately_owned_relationships002.htm
|info=y
+
}}
+
=One-to-Many Composite Collection Mapping
+
Use XML composite collection mappings to represent one-to-many relationships. Composite collection XML mappings can reference any class that has an EclipseLink descriptor. The attribute in the object mapped must implement either the Java <tt>Collection</tt> interface (for example, <tt>Vector</tt> or <tt>HashSet</tt>) or <tt>Map</tt> interface (for example, <tt>Hashtable</tt> or <tt>TreeMap</tt>). The <tt>CompositeCollectionMapping</tt> class allows a reference to the mapped class and the indexing type for that class.
+
 
+
Given the XML schema in this example, [[#Figure 58-27|XML Composite Collection Mapping]] illustrates an XML composite collection mapping to different elements by position in a corresponding XML document. [[#Example 58-49|Java for XML Composite Collection Mapping for a Collection Attribute]] shows how to configure this mapping in Java for a <tt>Collection</tt> attribute and [[#Example 58-50|Java for XML Composite Collection Mapping for a Map Attribute]] shows how to configure this mapping in Java for a <tt>Map</tt> attribute.
+
 
+
 
+
<span id="Example 58-48">
+
''''' Schema for XML Composite Collection Mapping'''''
+
<source lang="xml">
+
<?xml version="1.0" encoding="UTF-8"?>
+
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
+
    <xsd:element name="customer" type="customer-type"/>
+
    <xsd:complexType name="customer-type">
+
        <xsd:sequence>
+
+
            <xsd:element name="first-name" type="xsd:string"/>
+
            <xsd:element name="last-name" type="xsd:string"/>
+
            <xsd:element name="phone-number">
+
                <xsd:complexType>
+
                    <xsd:sequence>
+
                        <xsd:element name="number" type="xsd:string"/>
+
+
                    </xsd:sequence>
+
                    <xsd:attribute name="type" type="xsd:string"/>
+
                </xsd:complexType>
+
            </xsd:element>
+
        </xsd:sequence>
+
    </xsd:complexType>
+
+
</xsd:schema>
+
</source>
+
 
+
<span id="Figure 58-27"></span>
+
''''' XML Composite Collection Mapping'''''
+
 
+
[[Image:ccxm.gif|XML Composite Collection Mapping]]<br><br>
+
 
+
<span id="Example 58-49"></span>
+
''''' Java for XML Composite Collection Mapping for a Collection Attribute'''''
+
<source lang="java">
+
XMLCompositeCollectionMapping phoneNumbersMapping = new XMLCompositeCollectionMapping();
+
phoneNumbersMapping.setAttributeName("phoneNumbers");
+
phoneNumbersMapping.setXPath("phone-number");
+
phoneNumbersMapping.setReferenceClass(PhoneNumber.class);
+
</source>
+
 
+
 
+
<span id="Example 58-50"></span>
+
''''' Java for XML Composite Collection Mapping for a Map Attribute'''''
+
<source lang="java">
+
XMLCompositeCollectionMapping phoneNumbersMapping = new XMLCompositeCollectionMapping();
+
phoneNumbersMapping.setAttributeName("phoneNumbers");         
+
phoneNumbersMapping.setXPath("phone-number");
+
phoneNumbersMapping.setReferenceClass(PhoneNumber.class);
+
phoneNumbersMapping.useMapClass(HashMap.class, "getType");
+
</source>
+
 
+
{{EclipseLink_MOXy
+
}}
+

Latest revision as of 10:22, 8 November 2012

See http://www.eclipse.org/eclipselink/documentation/2.4/moxy/privately_owned_relationships002.htm