xhjwyy 2015-12-23 12:37 采纳率: 57.1%
浏览 1841
已采纳

HIbernate中我没有指定id最后却有id生成

 @Entity
@DiscriminatorValue("员工")
public class Employ extends Person4 {
    private String title;
    private double salary;
    @ManyToOne(cascade=CascadeType.ALL,targetEntity=Manger.class)
    @JoinColumn(name="manger_id",nullable=true)
    private Manger manger;

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public double getSalary() {
        return salary;
    }

    public void setSalary(double salary) {
        this.salary = salary;
    }



    public Manger getManger() {
        return manger;
    }

    public void setManger(Manger manger) {
        this.manger = manger;
    }




}
 @Entity
@DiscriminatorValue("经理")
public class Manger extends Employ {


    private String department;
    @OneToMany(cascade=CascadeType.ALL
            , mappedBy="manger" , targetEntity=Employ.class)
    private Set<Employ> employs=new HashSet<Employ>();
    public String getDepartment() {
        return department;
    }
    public void setDepartment(String department) {
        this.department = department;
    }
    public Set<Employ> getEmploys() {
        return employs;
    }
    public void setEmploys(Set<Employ> employs) {
        this.employs = employs;
    }




}

图片说明

  • 写回答

1条回答 默认 最新

  • xhjwyy 2015-12-24 03:24
    关注

    已解决,由于是使用父类映射所以虽然在manger类中没有指定主键id但由于是继承person类,其中有id主键,所以外键映射能成功

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?