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;
...
}