Java Reference
In-Depth Information
Notice that @OneToMany annotation has a mappedBy attribute, this attribute is
necessary since each of these relationships is bi-directional (we can access all
addresses for a customer, and for a given address, we can obtain what 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;
//imports omitted for brevity
@Entity
@Table(name = "ADDRESS")
@NamedQueries({
@NamedQuery(name = "Address.findAll",
query = "SELECT a FROM Address a"),
@NamedQuery(name = "Address.findByAddressId",
query = "SELECT a FROM Address a WHERE a.addressId = :addressId"),
@NamedQuery(name = "Address.findByAddrLine1",
query = "SELECT a FROM Address a WHERE a.addrLine1 = :addrLine1"),
@NamedQuery(name = "Address.findByAddrLine2",
query = "SELECT a FROM Address a WHERE a.addrLine2 = :addrLine2"),
@NamedQuery(name = "Address.findByCity",
query = "SELECT a FROM Address a WHERE a.city = :city"),
@NamedQuery(name = "Address.findByZip",
query = "SELECT a FROM Address a WHERE a.zip = :zip")})
public class Address implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@NotNull
@Column(name = "ADDRESS_ID")
private Integer addressId;
@Size(max = 100)
@Column(name = "ADDR_LINE_1")
private String addrLine1;
@Size(max = 100)
@Column(name = "ADDR_LINE_2")
private String addrLine2;
@Size(max = 100)
@Column(name = "CITY")
private String city;
@Size(max = 5)
@Column(name = "ZIP")
private String zip;
 
Search WWH ::




Custom Search