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/EmbeddedIdClass"

< EclipseLink‎ | Examples‎ | MOXy‎ | JPA
(New page: == Overview == == JPA Entities == <source lang="java"> @Entity public class PhoneNumber { @ManyToOne @JoinColumns({ @JoinColumn(name="E_ID", referencedColumnName = "E_ID...)
 
(JAXB Bindings)
Line 46: Line 46:
  
 
== JAXB Bindings ==
 
== 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.
 +
 +
<source lang="java">
 +
@XmlAccessorType(XmlAccessType.FIELD)
 +
package com.example.model;
 +
 +
import javax.xml.bind.annotation.XmlAccessType;
 +
import javax.xml.bind.annotation.XmlAccessorType;
 +
</source>

Revision as of 12:09, 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 {
 
    @EmbeddedId
    private EmployeeId id;
 
    @OneToMany(mappedBy="contact")
    @XmlInverseReference(mappedBy="contact")
    private List<PhoneNumber> contactNumber;
 
}
@Embeddable
public class EmployeeId {
 
    @Column(name="E_ID")
    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;

Back to the top