From Eclipsepedia

< EclipseLink‎ | Examples‎ | MOXy
Revision as of 15:56, 30 September 2009 by (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


This example demonstrates how to derive an XML representation from a set of JPA entities using JAXB.

JPA Entities

For this example the following JPA entities will be used. In order to save space package names, import statements, and the get /set methods have been omitted from the following code samples. All annotations shown below are standard JPA annotations.

public class Department {
    private BigDecimal dId;
    private String name;
    @JoinTable(name="DEPT_EMP", joinColumns = 
        @JoinColumn(name="D_ID", referencedColumnName = "D_ID"), 
            inverseJoinColumns = @JoinColumn(name="E_ID", 
                referencedColumnName = "E_ID"))
    private List<Employee> member;
public class Employee {
    private BigDecimal eId;
    private String name;
    private Address residence;
    private List<PhoneNumber> contactNumber;
    private List<Department> team;
public class Address {
    @Column(name="E_ID", insertable=false, updatable=false)
    private BigDecimal eId;
    private String city;
    private String street;
    private Employee resident;
public class PhoneNumber {
    private BigDecimal pId;
    @JoinColumn(name="E_ID", referencedColumnName = "E_ID")
    private Employee contact;
    private String num;