Java Reference
In-Depth Information
Notice that the @OneToMany annotation has a mappedBy attribute. This attribute
is necessary because each of these relationships is bidirectional (we can access all
addresses for a customer, and for a given address we can find out which customer it
belongs to). The value of this attribute must match the name of the field on the other
side of the relationship. Let's take a look at the Address entity to illustrate the other
side of the customer-address relationship.
package com.ensode.jpa;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
@Table(name = "ADDRESS")
@NamedQuery(name = "Address.findAll",
query = "SELECT a FROM Address a"),
@NamedQuery(name = "Address.findByAddressId",
query = "SELECT a FROM Address a WHERE a.addressId =
@NamedQuery(name = "Address.findByAddrLine1",
query = "SELECT a FROM Address a WHERE a.addrLine1 =
@NamedQuery(name = "Address.findByAddrLine2",
query = "SELECT a FROM Address a WHERE a.addrLine2 =
@NamedQuery(name = "Address.findByCity",
query = "SELECT a FROM Address a WHERE = :city"),
@NamedQuery(name = "Address.findByZip",
query = "SELECT a FROM Address a WHERE = :zip")})
public class Address implements Serializable {
private static final long serialVersionUID = 1L;
@Basic(optional = false)
Search WWH ::

Custom Search