Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "EclipseLink/Examples/MOXy/JPA/CompoundPrimaryKeys"
< EclipseLink | Examples | MOXy | JPA
(→JAXB Bindings) |
(→Overview) |
||
Line 1: | Line 1: | ||
== Overview == | == Overview == | ||
+ | |||
+ | This example demonstrates how to derive an XML representation from a set of JPA entities using JAXB when a JPA entity has compound primary keys. | ||
== JPA Entities == | == JPA Entities == |
Revision as of 12:10, 1 December 2009
Overview
This example demonstrates how to derive an XML representation from a set of JPA entities using JAXB when a JPA entity has compound primary keys.
JPA Entities
@Entity public class PhoneNumber { @ManyToOne @JoinColumns({ @JoinColumn(name="E_ID", referencedColumnName = "E_ID"), @JoinColumn(name="E_COUNTRY", referencedColumnName = "COUNTRY") }) @XmlIDREF private Employee contact; }
@Entity @IdClass(EmployeeId.class) public class Employee { @Id @Column(name="E_ID") @XmlID private BigDecimal eId; @Id @XmlID private String country; @OneToMany(mappedBy="contact") @XmlInverseReference(mappedBy="contact") private List<PhoneNumber> contactNumber; }
public class EmployeeId { private BigDecimal eId; private String country; }
JAXB Bindings
For this example the XML acessor type will be set to FIELD for all the model classes. This can be set as a package level JAXB annotation.
@XmlAccessorType(XmlAccessType.FIELD) package com.example.model; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType;