Java Tutorial/EJB3/EJB Query Language

Материал из Java эксперт
Перейти к: навигация, поиск

Use EJB QL To Retrieve Entity Bean

File: Customer.java



import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.IdClass;
@Entity
@IdClass(CustomerPK.class)
public class Customer implements java.io.Serializable {
  private String firstName;
  private String lastName;
  private long ssn;
  public String getFirstName() {
    return firstName;
  }
  public void setFirstName(String firstName) {
    this.firstName = firstName;
  }
  @Id
  public String getLastName() {
    return lastName;
  }
  public void setLastName(String lastName) {
    this.lastName = lastName;
  }
  @Id
  public long getSsn() {
    return ssn;
  }
  public void setSsn(long ssn) {
    this.ssn = ssn;
  }
}
class CustomerPK implements java.io.Serializable {
  private String lastName;
  private long ssn;
  public CustomerPK() {
  }
  public CustomerPK(String lastName, long ssn) {
    this.lastName = lastName;
    this.ssn = ssn;
  }
  public String getLastName() {
    return this.lastName;
  }
  public void setLastName(String lastName) {
    this.lastName = lastName;
  }
  public long getSsn() {
    return ssn;
  }
  public void setSsn(long ssn) {
    this.ssn = ssn;
  }
  public boolean equals(Object obj) {
    if (obj == this)
      return true;
    if (!(obj instanceof CustomerPK))
      return false;
    CustomerPK pk = (CustomerPK) obj;
    if (!lastName.equals(pk.lastName))
      return false;
    if (ssn != pk.ssn)
      return false;
    return true;
  }
  public int hashCode() {
    return lastName.hashCode() + (int) ssn;
  }
}