java

关注公众号 jb51net

关闭
首页 > 软件编程 > java > idea hibernate jpa 生成实体类

idea hibernate jpa 生成实体类的实现

作者:走过程序员的路

这篇文章主要介绍了idea hibernate jpa 生成实体类的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

本篇博客记录下 IDEA 中连接数据库反转生成 Hibernate 实体和配置文件。

1. 打开 DataBase 窗口,添加数据源




到了这一步数据源已添加好。

2. 添加 hibernat 持久层支持,生成实体 Bean /配置文件,这一步要去plugs那里下载一个hibernate插件,不然你的persistence是出不来的



然后选择数据源,选择包,添加生成 Bean 的后缀,选择表,选择生成 xml 配置文件还是注解。

OK,结束

如果你选择生成带 JPA 注解类,映射文件是可以省略的,相反如果你生成映射文件,JPA 注解也可以省略。

看你喜欢哪种方式

生成注解例子

@Entity
@Table(name = "user", schema = "db_test", catalog = "")
public class UserPO {
  private String uuid;
  private String name;
  private String passwd;
  private String sex;
  private Timestamp birthday;
  private String phone;
  private String photo;
  private String email;
  private String yxbz;
  private String sorts;
 
  @Id
  @Column(name = "UUID")
  public String getUuid() {
    return uuid;
  }
 
  public void setUuid(String uuid) {
    this.uuid = uuid;
  }
 
  @Basic
  @Column(name = "NAME")
  public String getName() {
    return name;
  }
 
  public void setName(String name) {
    this.name = name;
  }
 
  @Basic
  @Column(name = "PASSWD")
  public String getPasswd() {
    return passwd;
  }
 
  public void setPasswd(String passwd) {
    this.passwd = passwd;
  }
 
  @Basic
  @Column(name = "SEX")
  public String getSex() {
    return sex;
  }
 
  public void setSex(String sex) {
    this.sex = sex;
  }
 
  @Basic
  @Column(name = "BIRTHDAY")
  public Timestamp getBirthday() {
    return birthday;
  }
 
  public void setBirthday(Timestamp birthday) {
    this.birthday = birthday;
  }
 
  @Basic
  @Column(name = "PHONE")
  public String getPhone() {
    return phone;
  }
 
  public void setPhone(String phone) {
    this.phone = phone;
  }
 
  @Basic
  @Column(name = "PHOTO")
  public String getPhoto() {
    return photo;
  }
 
  public void setPhoto(String photo) {
    this.photo = photo;
  }
 
  @Basic
  @Column(name = "EMAIL")
  public String getEmail() {
    return email;
  }
 
  public void setEmail(String email) {
    this.email = email;
  }
 
  @Basic
  @Column(name = "YXBZ")
  public String getYxbz() {
    return yxbz;
  }
 
  public void setYxbz(String yxbz) {
    this.yxbz = yxbz;
  }
 
  @Basic
  @Column(name = "SORTS")
  public String getSorts() {
    return sorts;
  }
 
  public void setSorts(String sorts) {
    this.sorts = sorts;
  }
 
  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;
 
    UserPO userPO = (UserPO) o;
 
    if (uuid != null ? !uuid.equals(userPO.uuid) : userPO.uuid != null) return false;
    if (name != null ? !name.equals(userPO.name) : userPO.name != null) return false;
    if (passwd != null ? !passwd.equals(userPO.passwd) : userPO.passwd != null) return false;
    if (sex != null ? !sex.equals(userPO.sex) : userPO.sex != null) return false;
    if (birthday != null ? !birthday.equals(userPO.birthday) : userPO.birthday != null) return false;
    if (phone != null ? !phone.equals(userPO.phone) : userPO.phone != null) return false;
    if (photo != null ? !photo.equals(userPO.photo) : userPO.photo != null) return false;
    if (email != null ? !email.equals(userPO.email) : userPO.email != null) return false;
    if (yxbz != null ? !yxbz.equals(userPO.yxbz) : userPO.yxbz != null) return false;
    if (sorts != null ? !sorts.equals(userPO.sorts) : userPO.sorts != null) return false;
 
    return true;
  }
 
  @Override
  public int hashCode() {
    int result = uuid != null ? uuid.hashCode() : 0;
    result = 31 * result + (name != null ? name.hashCode() : 0);
    result = 31 * result + (passwd != null ? passwd.hashCode() : 0);
    result = 31 * result + (sex != null ? sex.hashCode() : 0);
    result = 31 * result + (birthday != null ? birthday.hashCode() : 0);
    result = 31 * result + (phone != null ? phone.hashCode() : 0);
    result = 31 * result + (photo != null ? photo.hashCode() : 0);
    result = 31 * result + (email != null ? email.hashCode() : 0);
    result = 31 * result + (yxbz != null ? yxbz.hashCode() : 0);
    result = 31 * result + (sorts != null ? sorts.hashCode() : 0);
    return result;
  }
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

您可能感兴趣的文章:
阅读全文