Community
Participate
Working Groups
In the 'standard' EclipseLink employee-address-phones model, the 'phone' object has 2 fields that make up its primary key: areaCode and phoneNumber. To represent this in XML, we would want both fields to be part of a foreign reference - something like: <employee-address-phones-model> <employee emp-id="10"> <first-name>Mike</first-name> <last-name>Norman</last-name> <address-ref id="20"/> <phones> <phone-ref area-code-id="613" phonenumber-id="228-1808" /> <phone-ref area-code-id="613" phonenumber-id="288-4638" /> </phones> However: XMLCollectionReferenceMapping phoneRef = new XMLCollectionReferenceMapping(); phoneRef.setAttributeName("phones"); phoneRef.setReferenceClass(Phone.class); phoneRef.addSourceToTargetKeyFieldAssociation( "phones/phone-ref/@area-code-id", "areaCode/text()"); phoneRef.addSourceToTargetKeyFieldAssociation( "phones/phone-ref/@phonenumber-id", "phonenumber/text()"); employeeDescriptor.addMapping(phoneRef); produces: <employee-address-phones-model> <employee emp-id="10"> <first-name>Mike</first-name> <last-name>Norman</last-name> <address-ref>20</address-ref> <phones> <phone-ref area-code-id="228-1808"/> <phone-ref area-code-id="288-4638"/> </phones> Only the first pk-field attribute (area-code) is printed for phoneRef. (NB - the same happens if the fields are elements)
Created attachment 150166 [details] Core Fix - WIP
Created attachment 150167 [details] MOXy Test Cases
*** Bug 292958 has been marked as a duplicate of this bug. ***
Created attachment 150292 [details] Core Fix
Created attachment 150308 [details] MOXy Test Cases
Created attachment 150310 [details] Core Fix
WRT the original use case, the following would be the corresponding mapping configuration: XMLCollectionReferenceMapping phoneRef = new XMLCollectionReferenceMapping(); phoneRef.setReferenceClass(Phone.class); phoneRef.setAttributeName("phones"); phoneRef.setXPath("phones"); phoneRef.addSourceToTargetKeyFieldAssociation("phone-ref/@area-code-id", "areaCode/text()"); phoneRef.addSourceToTargetKeyFieldAssociation("phone-ref/@phonenumber-id", "phonenumber/text()"); employeeDescriptor.addMapping(phoneRef); The XPath paramter on the mapping forms the grouping element, the fk is then comnposed of the field associations.
Created attachment 150400 [details] MOXy Test Cases
Created attachment 150634 [details] MOXy Test Cases
Created attachment 150974 [details] Core Fix
Created attachment 150976 [details] MOXy Test Cases
Created attachment 151083 [details] MOXy Test Cases
How was the fix implemented? Before work began on this bug, the unmarshal use case already worked, so this fix was focussed on the marshal use case. This fix is for only the SAX platform, the corresponding work for the DOM platform will be covered by bug #294072. A new node value called XMLCollectionReferenceMappingMarshalNodeValue has been introduced. This node value will be used for the marshal use case when the mapping has multiple foreign keys. This node value will build an XPathNode tree based on the specified foreign keys, then for each value in the collection that sub XPathNode tree will be marshalled.
Created attachment 151205 [details] MOXy Test Cases
Fix checked into trunk at rev: 5724 Code Reviewed By: Rick Barkhouse
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink