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

From Eclipsepedia

< EclipseLink‎ | Examples‎ | MOXy‎ | JPA
Jump to: navigation, search
Line 1: Line 1:
 +
== Overview ==
 +
 +
== JPA Entities ==
 +
 
<source lang="java">
 
<source lang="java">
 
@Entity
 
@Entity
Line 44: Line 48:
 
}
 
}
 
</source>
 
</source>
 +
 +
== JAXB Bindings ==

Revision as of 11:59, 1 December 2009

Overview

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;
 
}
@Entity
public class EmployeeId {
 
    private BigDecimal eId;
    private String country;
 
}

JAXB Bindings