前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >JPA JPQL/持久化查询语言

JPA JPQL/持久化查询语言

作者头像
一个会写诗的程序员
发布2018-08-17 15:06:17
6390
发布2018-08-17 15:06:17
举报
代码语言:javascript
复制
@NamedQuery(query = "Select e from Employee e where e.eid = :id", 
   name = "find employee by id")
代码语言:javascript
复制
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 关系

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017.08.12 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档