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.
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 |
||
Line 4: | Line 4: | ||
|eclipselink=y | |eclipselink=y | ||
|eclipselinktype=MOXy | |eclipselinktype=MOXy | ||
+ | |api=y | ||
+ | |apis= * [http://www.eclipse.org/eclipselink/api/latest/javax/xml/bind/annotation/XmlInverseReference.html XmlInverseReference] | ||
}} | }} | ||
Revision as of 10:17, 23 May 2011
EclipseLink MOXy
EclipseLink | |
Website | |
Download | |
Community | |
Mailing List • Forums • IRC • mattermost | |
Issues | |
Open • Help Wanted • Bug Day | |
Contribute | |
Browse Source |
Key API
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.
@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; }
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.
@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; }