Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "EclipseLink/Examples/MOXy/JPA"

(New page: == Overview == 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 b...)
 
(JPA Entities)
Line 84: Line 84:
 
}
 
}
 
</source>
 
</source>
 +
 +
== JAXB Binding ==
 +
 +
=== Relationship – One To One (Containment) ===
 +
 +
This relationship applies when an object privately owns another data object.
 +
 +
=== Relationship – One To One (Non-Containment) ===
 +
 +
This relationship applies when an object references but does not privately own another data object.
 +
 +
=== Relationship – One To Many (Containment) ===
 +
 +
This relationship applies when an object privately owns a collection of data objects.
 +
 +
=== Relationship – One To Many (Non-Containment) ===
 +
 +
This relationship applies when an object references but does not privately own a collection of data objects.

Revision as of 15:59, 30 September 2009

Overview

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.

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

JAXB Binding

Relationship – One To One (Containment)

This relationship applies when an object privately owns another data object.

Relationship – One To One (Non-Containment)

This relationship applies when an object references but does not privately own another data object.

Relationship – One To Many (Containment)

This relationship applies when an object privately owns a collection of data objects.

Relationship – One To Many (Non-Containment)

This relationship applies when an object references but does not privately own a collection of data objects.

Back to the top