Community
Participate
Working Groups
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
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);
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.
Created attachment 151202 [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