Bug 294063 - Enhancement Request - Add support for key classes
Summary: Enhancement Request - Add support for key classes
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Blaise Doughan CLA
QA Contact:
URL:
Whiteboard:
Keywords: Documentation
Depends on: 285889
Blocks:
  Show dependency tree
 
Reported: 2009-11-03 09:16 EST by Blaise Doughan CLA
Modified: 2022-06-09 10:05 EDT (History)
1 user (show)

See Also:


Attachments
MOXy Test Cases (105.39 KB, patch)
2009-11-03 10:19 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 Blaise Doughan CLA 2009-11-03 09:16:25 EST
JPA has the concept of an embedded ID.  This is where an object with one or more fields/properties represents the key information for the owning object, see example below:

@Entity
public class Employee {
     @EmbeddedId private EmployeeID id;
     ...
}

@Embeddable
public class EmployeeID {
     private String country;
     private int id;
     ...
}

What is required in MOXy is the ability to use this ORM key information in the OXM key based mappings XMLObjectReferenceMapping and XMLCollectionReferenceMapping
Comment 1 Blaise Doughan CLA 2009-11-03 09:26:40 EST
How is the metadata specified?

No new metadata is required.  The embedded ID is mapped using an XMLCompositeObjectMapping, and the ID fields are specified on the owning descriptor, see the example below:

XMLDescriptor employeeDescriptor = new XMLDescriptor();
employeeDescriptor.setJavaClass(Employee.class);
employeeDescriptor.addPrimaryKeyFieldName("country/text()");
employeeDescriptor.addPrimaryKeyFieldName("@id");

XMLCompositeObjectMapping idMapping = new XMLCompositeObjectMapping();
idMapping.setAttributeName("id");
idMapping.setXPath(".");
idMapping.setReferenceClass(EmployeeID.class);
employeeDescriptor.addMapping(idMapping);

---

XMLDescriptor employeeIDDescriptor = new XMLDescriptor();
employeeIDDescriptor.setJavaClas(EmployeeID.class);

XMLDirectMapping countryMapping = new XMLDirectMapping();
countryMapping.setAttributeName("country");
countryMapping.setXPath("country/text()");
employeeIDDescriptor.addMapping(countryMapping);

XMLDirectMapping idMapping = new XMLDirectMapping();
idMapping.setAttributeName("id");
idMapping.setXPath("@id");
employeeIDDescriptor.addMapping(idMapping);
Comment 2 Blaise Doughan CLA 2009-11-03 09:59:20 EST
How is it implemented?

If the primary key fields are not mapped directly by the descriptor then the getValueByXPath methods will be used to query the primary key data.
Comment 3 Blaise Doughan CLA 2009-11-03 10:19:19 EST
Created attachment 151202 [details]
MOXy Test Cases
Comment 4 Blaise Doughan CLA 2009-11-03 11:55:22 EST
Fix checked into trunk at rev:  5724
Code Reviewed By:  Rick Barkhouse
Comment 5 Eclipse Webmaster CLA 2022-06-09 10:05:39 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink