配置持久化实体
configurate the persistance entities
enter image description here
我正在为一个已经存在的项目使用 Java Persistence API,如图所示,根据他的 id.Before 我已经使用过,每个保证都有一个相对的雇员hibernate 逆向工程以生成实体,但我不知道如何处理这个 case.If 可以帮助我 link "Adminisitrateur" 实体以确保相同的实体在其他每个学期 "administrateur" 都有亲戚向我保证,如果可能的话,我会感激不尽。
这里是实体的持久化代码:
用户实体:
package persistence;
import java.io.Serializable;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
@Entity(name = "User")
public class User implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
private String name;
private String prenom;
@Column(unique = true)
private String matricule;
private String password;
@Column(unique = true)
private String email;
@OneToMany(mappedBy = "employer", fetch = FetchType.EAGER)
private Set<Demande> demandes;
private static final long serialVersionUID = 1L;
public User() {
}
public User(String name, String prenom, String matricule, String password, String email) {
super();
this.name = name;
this.prenom = prenom;
this.matricule = matricule;
this.password = password;
this.email = email;
}
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 String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public Set<Demande> getDemandes() {
return demandes;
}
public void setDemandes(Set<Demande> demandes) {
this.demandes = demandes;
}
public String getPrenom() {
return prenom;
}
public void setPrenom(String prenom) {
this.prenom = prenom;
}
public String getMatricule() {
return matricule;
}
public void setMatricule(String matricule) {
this.matricule = matricule;
}
public static long getSerialversionuid() {
return serialVersionUID;
}
}
雇主实体:
package persistence;
import java.io.Serializable;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.OneToMany;
/**
* Entity implementation class for Entity: Employer
*
*/
@Entity
public class Employer extends User implements Serializable {
@OneToMany(mappedBy = "employerRelative", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
private List<Assure> assures;
private static final long serialVersionUID = 1L;
public Employer() {
}
public Employer(String name, String prenom, String matricule, String password, String email) {
super(name, prenom, matricule, password, email);
}
public List<Assure> getAssures() {
return assures;
}
public void setAssures(List<Assure> assures) {
this.assures = assures;
}
public void linkAssures(List<Assure> assures) {
this.assures = assures;
for (Assure a : assures) {
a.setEmployerRelative(this);
}
}
public static long getSerialversionuid() {
return serialVersionUID;
}
}
管理员实体:
package persistence;
import java.io.Serializable;
import javax.persistence.*;
import persistence.User;
/**
* Entity implementation class for Entity: Administrateur
*
*/
@Entity
public class Administrateur extends User implements Serializable {
private static final long serialVersionUID = 1L;
public Administrateur() {
super();
}
public Administrateur(String name, String prenom, String login, String password, String email) {
super(name, prenom, login, password, email);
// TODO Auto-generated constructor stub
}
}
保证实体:
包持久性;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
/**
* Entity implementation class for Entity: Assure
*
*/
@Entity
public class Assure extends User implements Serializable {
@ManyToOne
private Employer employerRelative;
private String type;
private static final long serialVersionUID = 1L;
public Assure() {
super();
}
public Assure(String name, String prenom, String matricule, String password, String email) {
super(name, prenom, matricule, password, email);
}
public Employer getEmployerRelative() {
return employerRelative;
}
public void setEmployerRelative(Employer employerRelative) {
this.employerRelative = employerRelative;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
这里我们讨论的是来自用户 class 的扩展。使用休眠用户 class 执行此操作不应使用 @Entity
进行注释。你应该使用 @MappedSupperClass
或更好的 @Inheritance
注释。
enter image description here
我正在为一个已经存在的项目使用 Java Persistence API,如图所示,根据他的 id.Before 我已经使用过,每个保证都有一个相对的雇员hibernate 逆向工程以生成实体,但我不知道如何处理这个 case.If 可以帮助我 link "Adminisitrateur" 实体以确保相同的实体在其他每个学期 "administrateur" 都有亲戚向我保证,如果可能的话,我会感激不尽。
这里是实体的持久化代码: 用户实体:
package persistence;
import java.io.Serializable;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
@Entity(name = "User")
public class User implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
private String name;
private String prenom;
@Column(unique = true)
private String matricule;
private String password;
@Column(unique = true)
private String email;
@OneToMany(mappedBy = "employer", fetch = FetchType.EAGER)
private Set<Demande> demandes;
private static final long serialVersionUID = 1L;
public User() {
}
public User(String name, String prenom, String matricule, String password, String email) {
super();
this.name = name;
this.prenom = prenom;
this.matricule = matricule;
this.password = password;
this.email = email;
}
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 String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public Set<Demande> getDemandes() {
return demandes;
}
public void setDemandes(Set<Demande> demandes) {
this.demandes = demandes;
}
public String getPrenom() {
return prenom;
}
public void setPrenom(String prenom) {
this.prenom = prenom;
}
public String getMatricule() {
return matricule;
}
public void setMatricule(String matricule) {
this.matricule = matricule;
}
public static long getSerialversionuid() {
return serialVersionUID;
}
}
雇主实体:
package persistence;
import java.io.Serializable;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.OneToMany;
/**
* Entity implementation class for Entity: Employer
*
*/
@Entity
public class Employer extends User implements Serializable {
@OneToMany(mappedBy = "employerRelative", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
private List<Assure> assures;
private static final long serialVersionUID = 1L;
public Employer() {
}
public Employer(String name, String prenom, String matricule, String password, String email) {
super(name, prenom, matricule, password, email);
}
public List<Assure> getAssures() {
return assures;
}
public void setAssures(List<Assure> assures) {
this.assures = assures;
}
public void linkAssures(List<Assure> assures) {
this.assures = assures;
for (Assure a : assures) {
a.setEmployerRelative(this);
}
}
public static long getSerialversionuid() {
return serialVersionUID;
}
}
管理员实体:
package persistence;
import java.io.Serializable;
import javax.persistence.*;
import persistence.User;
/**
* Entity implementation class for Entity: Administrateur
*
*/
@Entity
public class Administrateur extends User implements Serializable {
private static final long serialVersionUID = 1L;
public Administrateur() {
super();
}
public Administrateur(String name, String prenom, String login, String password, String email) {
super(name, prenom, login, password, email);
// TODO Auto-generated constructor stub
}
}
保证实体: 包持久性;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
/**
* Entity implementation class for Entity: Assure
*
*/
@Entity
public class Assure extends User implements Serializable {
@ManyToOne
private Employer employerRelative;
private String type;
private static final long serialVersionUID = 1L;
public Assure() {
super();
}
public Assure(String name, String prenom, String matricule, String password, String email) {
super(name, prenom, matricule, password, email);
}
public Employer getEmployerRelative() {
return employerRelative;
}
public void setEmployerRelative(Employer employerRelative) {
this.employerRelative = employerRelative;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
这里我们讨论的是来自用户 class 的扩展。使用休眠用户 class 执行此操作不应使用 @Entity
进行注释。你应该使用 @MappedSupperClass
或更好的 @Inheritance
注释。