| Summary: | Enhancement: support @XmlInverseReference with @XmlElementRef | ||||||
|---|---|---|---|---|---|---|---|
| Product: | z_Archived | Reporter: | Blaise Doughan <blaise.doughan> | ||||
| Component: | Eclipselink | Assignee: | Matt MacIvor <matt.macivor> | ||||
| Status: | RESOLVED FIXED | QA Contact: | |||||
| Severity: | normal | ||||||
| Priority: | P3 | CC: | matt.macivor, mpol | ||||
| Version: | unspecified | ||||||
| Target Milestone: | --- | ||||||
| Hardware: | PC | ||||||
| OS: | Windows XP | ||||||
| Whiteboard: | |||||||
| Attachments: |
|
||||||
Implementation Notes: - To support this use case we will need to support XMLInverseReferenceMapping on XMLChoiceObjectMapping and XMLChoiceCollectionMapping. - oxm.xml and schema will need to be updated to support this configuration. Is there any chance that the target for this will be moved to 2.4.0? This is apparently exactly what I miss right at the moment (except between two different classes in my case). Or maybe I am mistaken? Because I was able to describe my use case with the current external metadata schema, it only does not work. <java-type name="Parent"> <java-attributes> <xml-element-ref java-attribute="children"/> </java-attributes> </java-type> <java-type name="Child"> <java-attributes> <xml-inverse-reference mapped-by="children" java-attribute="parent" xml-accessor-type="FIELD"/> </java-attributes> </java-type> I tried this in the latest Trunk and 2.4 streams and it seems to work. I attempted both with annotations using the object model Blaise provided and with the external bindings Michal provided and in both cases, the unmarshal worked and the backpointer seemed to be set correctly. I guessed a little at the object model based on the xml bindings. package bug370573; import java.util.List; import javax.xml.bind.annotation.XmlRootElement; @XmlRootElement public class Parent { public List<Child> children; } package bug370573; import javax.xml.bind.annotation.XmlRootElement; @XmlRootElement public class Child { Parent parent; } ... <java-type name="Parent"> <java-attributes> <xml-element-ref java-attribute="children"/> </java-attributes> </java-type> <java-type name="Child"> <java-attributes> <xml-inverse-reference mapped-by="children" java-attribute="parent" xml-accessor-type="FIELD"/> </java-attributes> </java-type> ... Unmarshalling the following xml document: <parent> <child/> <child/> </parent> Using these classes and external bindings on the latest trunk everything seems to work. Can you verify that this problem still persists for you on the latest 2.4 or trunk nightly? It may have been resolved by the fixes for another inverse-reference bug that has been checked in recently. Tested with eclipselink-2.4.0-20120525.052533-3357.jar
It indeed works with the basic model, but unfortunately fails for subclasses of Child.
After adding a trivial subclass to the context
@XmlRootElement
public class ChildSubclass extends Child {}
and after unmarshaling
<parent>
<child/>
<childSubclass/>
</parent>
the first list element has the backlink to parent set, the second one does not.
Created attachment 216315 [details]
Propsed fix and tests
Looks like it works in the latest 2.4.0 nightly. Thank you. Unfortunately it turns out that I have also a case where I have to combine element refs and inverse references with adapters, and this does not seem to work, even though inverse references from adapted classes work with regular xml-element mappings. I will describe this case in a separate bugreport. (In reply to comment #6) > I will describe this case in a separate bugreport. The bug 380803 Attached patch checked in to SVN. Closing bug as fixed, since additional issues with xml-inverse-reference are being treated as a separate bug. The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink |
Since the values of a property are all related through an inheritance relationship, the following use case should be supported. import java.util.*; import javax.xml.bind.annotation.*; import org.eclipse.persistence.oxm.annotations.XmlInverseReference; @XmlRootElement @XmlAccessorType(XmlAccessType.FIELD) public class Parent { @XmlInverseReference(mappedBy="children") private Parent parent; @XmlElementRef private Set<Parent> children = new HashSet<Parent>(); }