Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » XmlInverseReference without the need for mappedBy attribute(Accomplishing bidirectional relationships without the need for the mappedBy attribute)
XmlInverseReference without the need for mappedBy attribute [message #698554] Tue, 19 July 2011 17:15 Go to next message
Paul Mooney is currently offline Paul MooneyFriend
Messages: 2
Registered: July 2011
Junior Member
Is there a way in Moxy to accomplish bidirectional relationships without the need to specify the 'mappedBy' attribute in the child class?

It seems the current implementation restricts the child class, in such a way that it is not a reusable class under mulitple parents. Or for that matter, it's not even reusable under the same parent, but for different groupings of values.

eg. Suppose we have the child class PhoneNumber:

public class PhoneNumber {
    ...
    @XmlInverseReference() //note: 'mappedBy' not present
    public Employee owningEmployee;
    ...
 }


and the Parent class employee, that reuses the PhoneNumber class:
@XmlRootElement(name="employee")
 public class Employee {
    ...
    @XmlElementWrapper(name="home-phone-numbers")
    @XmlElement(name="number")
    public List<PhoneNumber> homePhoneNumbers;


    @XmlElementWrapper(name="mobile-phone-numbers")
    @XmlElement(name="number")
    public List<PhoneNumber> mobilePhoneNumbers;
    ...
 }


I don't know if there is a way to accomplish this currently in Moxy. It doesn't seem to me that the child class should need to know anything about the parent, especially the property that references that child. In fact, we could say that the child doesn't even need to know the parent type. eg.


public class PhoneNumber {
    ...
    @XmlInverseReference() //note: mapped by not present
    public <T extends ?> T owningEmployee;
    ...
 }


This might (?) even work JPA style, where the 'one' side of the 'one-to-many' relationship specifies the mappedBy attribute . eg.
@XmlRootElement(name="employee")
 public class Employee {
    ...
    @XmlElementWrapper(name="home-phone-numbers")
    @XmlElement(name="number")
    @XmlMappedBy("owningEmployee")
    public List<PhoneNumber> homePhoneNumbers;


    @XmlElementWrapper(name="mobile-phone-numbers")
    @XmlElement(name="number")
    @XmlMappedBy("owningEmployee")
    public List<PhoneNumber> mobilePhoneNumbers;
    ...
 }
Re: XmlInverseReference without the need for mappedBy attribute [message #699098 is a reply to message #698554] Wed, 20 July 2011 20:18 Go to previous message
Blaise Doughan is currently offline Blaise DoughanFriend
Messages: 163
Registered: July 2009
Senior Member

Hi Paul,

Currently the 'mappedBy' property on @XmlInverseReferenceMapping is required. I definitely see the advantages of not requiring it. I have added the following enhancement request that you can use to track our progress on this issue:

- Bug 352673 - Enhancement: @XmlInverseReference without mappedBy property

-Blaise
Previous Topic:Conditional LEFT JOIN criteria API
Next Topic:eclipselink 2.3.0 on maven repo
Goto Forum:
  


Current Time: Tue Apr 23 08:56:04 GMT 2024

Powered by FUDForum. Page generated in 0.03197 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top