美文网首页
hibernate继承关系映射的JPA方式实现 ——JOINED

hibernate继承关系映射的JPA方式实现 ——JOINED

作者: 我我我我我_a70b | 来源:发表于2019-05-06 21:38 被阅读0次

    package entity;

    import javax.persistence.*;

    @Entity
    @Inheritance(strategy = InheritanceType.JOINED)

    public class Person {
    private int id;
    private String name;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)

    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;
    }
    

    }

    package entity;

    import javax.persistence.DiscriminatorValue;
    import javax.persistence.Entity;

    @Entity
    public class Teacher extends Person{

    private String tittle;
    
    public String getTittle() {
        return tittle;
    }
    
    public void setTittle(String tittle) {
        this.tittle = tittle;
    }
    

    }

    package entity;

    import javax.persistence.DiscriminatorValue;
    import javax.persistence.Entity;

    @Entity
    public class Student extends Person {
    private int score;

    public int getScore() {
        return score;
    }
    
    public void setScore(int score) {
        this.score = score;
    }
    

    }

    相关文章

      网友评论

          本文标题:hibernate继承关系映射的JPA方式实现 ——JOINED

          本文链接:https://www.haomeiwen.com/subject/jmjjoqtx.html