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/UserGuide/MOXy/Mapping JPA Entities to XML/Bidirectional Relationships"

m (New page: {{EclipseLink_UserGuide |info=y |toc=y |eclipselink=y |eclipselinktype=MOXy }} ==Relationships - Privately Owned== These relationships apply when the target object(s) is referenced by onl...)
 
m (Replacing page with ''''Warning This page is obsolete. Please see ''[http://www.eclipse.org/eclipselink/documentation/ Developing JAXB Applications Using EclipseLink M...')
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
{{EclipseLink_UserGuide
+
'''[[Image:Elug_draft_icon.png|Warning]] This page is obsolete. Please see ''[http://www.eclipse.org/eclipselink/documentation/ Developing JAXB Applications Using EclipseLink MOXy]'' for current information.'''
|info=y
+
|toc=y
+
|eclipselink=y
+
|eclipselinktype=MOXy
+
}}
+
 
+
==Relationships - Privately Owned==
+
These relationships apply when the target object(s) is referenced by only a single source object. This type of relationship can be safely represented as ''nesting'' in XML (the default in JAXB).
+
 
+
===One To One and Embedded===
+
In JPA, the '''OneToOne''' and '''Embedded''' annotations indicate only ''one'' instance of the source entity is able to refer to the same target entity instance. Since the relationship between '''Employee''' and '''Address''' is bi-directional, use the EclipseLink extension '''@XmlInverseReference''' to represent the back-pointer.
+
 
+
<source lang="java">
+
@Entity
+
public class Employee {
+
+
    @OneToOne(mappedBy="resident")
+
    private Address residence;
+
+
}
+
 
+
@Entity
+
public class Address {
+
+
    @OneToOne
+
    @JoinColumn(name="E_ID")
+
    @XmlInverseReference(mappedBy="residence")
+
    private Employee resident;
+
+
}
+
</source>
+
 
+
===One To Many===
+
In JPA, the '''OneToMany''' annotation indicates that only one instance of the source entity can refer to the same target entity instance. Since the relationship between '''Employee''' and '''Address''' is bi-directional, use the EclipseLink extension '''@XmlInverseReference''' to map the back-pointer.
+
 
+
<source lang="java">
+
@Entity
+
public class Employee {
+
+
    @OneToMany(mappedBy="contact")
+
    private List<PhoneNumber> contactNumber;
+
+
}
+
 
+
@Entity
+
public class PhoneNumber {
+
+
    @ManyToOne
+
    @JoinColumn(name="E_ID", referencedColumnName = "E_ID")
+
    @XmlInverseReference(mappedBy="contactNumber")
+
    private Employee contact;
+
+
}
+
 
+
</source>
+
 
+
 
+
 
+
{{EclipseLink_MOXy
+
|previous=    [[EclipseLink/UserGuide/MOXy/Mapping_JPA_Entities_to_XML/Lazily_Loaded_Fields/Properties|Properties]]
+
|next= [[EclipseLink/UserGuide/MOXy/Mapping_JPA_Entities_to_XML/Keys_and_Foreign_Keys|Keys and Foreign Keys]]
+
|up=      [[EclipseLink/UserGuide/MOXy/Mapping_JPA_Entities_to_XML|Mapping JPA Entities to XML]]
+
|version=2.2.0 DRAFT}}
+

Latest revision as of 13:13, 30 January 2013

Warning This page is obsolete. Please see Developing JAXB Applications Using EclipseLink MOXy for current information.

Copyright © Eclipse Foundation, Inc. All Rights Reserved.