Bug 285889 - XMLCollectionReferenceMapping does not handle composite primary keys
Summary: XMLCollectionReferenceMapping does not handle composite primary keys
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Blaise Doughan CLA
QA Contact:
URL:
Whiteboard:
Keywords: Documentation
: 292958 (view as bug list)
Depends on:
Blocks: 294072 294063
  Show dependency tree
 
Reported: 2009-08-06 11:02 EDT by Mike Norman CLA
Modified: 2022-06-09 10:08 EDT (History)
2 users (show)

See Also:


Attachments
Core Fix - WIP (18.76 KB, patch)
2009-10-21 16:52 EDT, Blaise Doughan CLA
no flags Details | Diff
MOXy Test Cases (61.50 KB, patch)
2009-10-21 16:53 EDT, Blaise Doughan CLA
no flags Details | Diff
Core Fix (20.00 KB, patch)
2009-10-22 15:03 EDT, Blaise Doughan CLA
no flags Details | Diff
MOXy Test Cases (111.09 KB, patch)
2009-10-22 16:39 EDT, Blaise Doughan CLA
no flags Details | Diff
Core Fix (20.70 KB, patch)
2009-10-22 16:44 EDT, Blaise Doughan CLA
no flags Details | Diff
MOXy Test Cases (148.38 KB, patch)
2009-10-23 15:20 EDT, Blaise Doughan CLA
no flags Details | Diff
MOXy Test Cases (193.93 KB, patch)
2009-10-27 10:46 EDT, Blaise Doughan CLA
no flags Details | Diff
Core Fix (32.86 KB, patch)
2009-10-30 15:54 EDT, Blaise Doughan CLA
no flags Details | Diff
MOXy Test Cases (279.06 KB, patch)
2009-10-30 15:59 EDT, Blaise Doughan CLA
no flags Details | Diff
MOXy Test Cases (299.05 KB, patch)
2009-11-02 10:47 EST, Blaise Doughan CLA
no flags Details | Diff
MOXy Test Cases (201.63 KB, patch)
2009-11-03 10:22 EST, Blaise Doughan CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Mike Norman CLA 2009-08-06 11:02:11 EDT
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)
Comment 1 Blaise Doughan CLA 2009-10-21 16:52:48 EDT
Created attachment 150166 [details]
Core Fix - WIP
Comment 2 Blaise Doughan CLA 2009-10-21 16:53:43 EDT
Created attachment 150167 [details]
MOXy Test Cases
Comment 3 Blaise Doughan CLA 2009-10-21 16:55:32 EDT
*** Bug 292958 has been marked as a duplicate of this bug. ***
Comment 4 Blaise Doughan CLA 2009-10-22 15:03:49 EDT
Created attachment 150292 [details]
Core Fix
Comment 5 Blaise Doughan CLA 2009-10-22 16:39:14 EDT
Created attachment 150308 [details]
MOXy Test Cases
Comment 6 Blaise Doughan CLA 2009-10-22 16:44:11 EDT
Created attachment 150310 [details]
Core Fix
Comment 7 Blaise Doughan CLA 2009-10-22 16:51:53 EDT
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.
Comment 8 Blaise Doughan CLA 2009-10-23 15:20:27 EDT
Created attachment 150400 [details]
MOXy Test Cases
Comment 9 Blaise Doughan CLA 2009-10-27 10:46:54 EDT
Created attachment 150634 [details]
MOXy Test Cases
Comment 10 Blaise Doughan CLA 2009-10-30 15:54:37 EDT
Created attachment 150974 [details]
Core Fix
Comment 11 Blaise Doughan CLA 2009-10-30 15:59:53 EDT
Created attachment 150976 [details]
MOXy Test Cases
Comment 12 Blaise Doughan CLA 2009-11-02 10:47:18 EST
Created attachment 151083 [details]
MOXy Test Cases
Comment 13 Blaise Doughan CLA 2009-11-03 10:13:36 EST
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.
Comment 14 Blaise Doughan CLA 2009-11-03 10:22:57 EST
Created attachment 151205 [details]
MOXy Test Cases
Comment 15 Blaise Doughan CLA 2009-11-03 11:56:04 EST
Fix checked into trunk at rev:  5724
Code Reviewed By:  Rick Barkhouse
Comment 16 Eclipse Webmaster CLA 2022-06-09 10:04:23 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink
Comment 17 Eclipse Webmaster CLA 2022-06-09 10:08:11 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink