Java Tutorial/JPA/Basic

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

Mark Field As Basic

File: Student.java



import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class Student {
  @Id
  private long id = System.currentTimeMillis();
  @Basic
  private String name;
  @Basic
  private Date dateOfBirth = new Date();
  public Date getDateOfBirth() {
    return dateOfBirth;
  }
  public void setDateOfBirth(Date dateOfBirth) {
    this.dateOfBirth = dateOfBirth;
  }
  public long getId() {
    return id;
  }
  public void setId(long id) {
    this.id = id;
  }
  public String getName() {
    return name;
  }
  public void setName(String name) {
    this.name = name;
  }
  
  
}





Mark Field As Lazy Load

File: Student.java



import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.Lob;
@Entity
public class Student {
  @Id
  private int id = 0;
  private String name;
  @Basic(fetch = FetchType.LAZY)
  @Lob
  private byte[] picture;
  public int getId() {
    return id;
  }
  public void setId(int id) {
    this.id = id;
  }
  public String getName() {
    return name;
  }
  public void setName(String name) {
    this.name = name;
  }
  public byte[] getPicture() {
    return picture;
  }
  public void setPicture(byte[] picture) {
    this.picture = picture;
  }
  public String toString() {
    return "\n\nID:" + id + "\nName:" + name + "\n\n";
  }
}