Jpa实体条件关系映射?

时间:2019-05-08 00:00:39

标签: java jpa uml entity-relationship

我有个人班和区域班。

如果“人员类型”是负责任的,则应应用一对一双向。

如果“人员类型”为“花园”,则应使用“一对多”。

有没有办法做到这一点??

对于初学者,我想提供此功能,但@Where注释似乎无法识别:

    @Entity

public class Personnel implements Serializable {



    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int Id;
    private String nom;
    private String prenom;
    private int Age;
    private Date dateDeRecretement;
    private String Login;
    private String password;
    @Enumerated(EnumType.STRING)
    private TypePoste poste;

    @Where(clause = "poste = 'GARDE_NUIT'")
    @ManyToOne
    private Zone zone;


    @Where(clause = "poste = 'GARDE_JOUR'")
    @ManyToOne
    private Zone zone1;


    @Where(clause = "poste = 'RESPONSABLE'")
    @ManyToOne
    private Zone zone2;

    private static final long serialVersionUID = 1L;

    public Personnel() {
        super();
    }   
    public int getId() {
        return this.Id;
    }

    public void setId(int Id) {
        this.Id = Id;
    }   
    public String getNom() {
        return this.nom;
    }

    public void setNom(String nom) {
        this.nom = nom;
    }   
    public String getPrenom() {
        return this.prenom;
    }

    public void setPrenom(String prenom) {
        this.prenom = prenom;
    }   
    public int getAge() {
        return this.Age;
    }

    public void setAge(int Age) {
        this.Age = Age;
    }   
    public Date getDateDeRecretement() {
        return this.dateDeRecretement;
    }

    public void setDateDeRecretement(Date dateDeRecretement) {
        this.dateDeRecretement = dateDeRecretement;
    }   
    public String getLogin() {
        return this.Login;
    }

    public void setLogin(String Login) {
        this.Login = Login;
    }   
    public String getPassword() {
        return this.password;
    }

    public void setPassword(String password) {
        this.password = password;
    }   
    public TypePoste getPoste() {
        return this.poste;
    }

    public void setPoste(TypePoste poste) {
        this.poste = poste;
    }
    public Zone getZone() {
        return zone;
    }
    public void setZone(Zone zone) {
        this.zone = zone;
    }
    public Zone getZone1() {
        return zone1;
    }
    public void setZone1(Zone zone1) {
        this.zone1 = zone1;
    }
    public Zone getZone2() {
        return zone2;
    }
    public void setZone2(Zone zone2) {
        this.zone2 = zone2;
    }

}

这是表示我要实现的目标的UML图。

UML Diagram To Achieve

1 个答案:

答案 0 :(得分:0)

您可以添加一个简单的约束,例如

enter image description here

可以肯定地将此约束写为一个不错的OCL。但是a)我对OCL不太了解,b)编码人员应该能够以这种方式正确实现它。