JPA JPQL/持久化查询语言

@NamedQuery(query = "Select e from Employee e where e.eid = :id", 
   name = "find employee by id")
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

@Entity
@Table
@NamedQuery(query = "Select e from Employee e where e.eid = :id", 
   name = "find employee by id")
public class Employee 
{
   @Id
   @GeneratedValue(strategy= GenerationType.AUTO)   
   private int eid;
   private String ename;
   private double salary;
   private String deg;
   public Employee(int eid, String ename, double salary, String deg) 
   {
    super( );
    this.eid = eid;
    this.ename = ename;
    this.salary = salary;
    this.deg = deg;
   }
   public Employee( ) 
   {
    super();
   }
   
   public int getEid( ) 
   {
    return eid;
   }
   public void setEid(int eid)  
   {
    this.eid = eid;
   }
   
   public String getEname( ) 
   {
    return ename;
   }
   public void setEname(String ename) 
   {
    this.ename = ename;
   }
   
   public double getSalary( ) 
   {
    return salary;
   }
   public void setSalary(double salary) 
   {
    this.salary = salary;
   }
   
   public String getDeg( ) 
   {
    return deg;
   }
   public void setDeg(String deg) 
   {
    this.deg = deg;
   }
   @Override
   public String toString() {
    return "Employee [eid=" + eid + ", ename=" + ename + ", salary="
            + salary + ", deg=" + deg + "]";
   }
}

实体类之间的关系如下:

@ManyToOne 关系
@OneToMany 关系
@OneToOne 关系
@ManyToMany 关系

你可能感兴趣的:(JPA JPQL/持久化查询语言)