在hibernate中应用实体之间的所有关联吗?

时间:2014-05-05 05:09:52

标签: java hibernate annotations

我无法确定类型:java.util.Set,在表:employee,对于列:[org.hibernate.mapping.Column(employeeAddresses)]。所以我有两个实体,比如

  1. 员工:


    EMPLOYEE_ID(PK), 员工姓名, employee_type(FK),

  2. EmployeeAddress:


    employee_address_id, land_no, 手机号码, address_type(fk), employee_id(fk)

  3. 当我尝试应用一对多和多对一关联时。我超越了异常。

1 个答案:

答案 0 :(得分:0)

你必须从Emoloyee实体写下你的onetomany关系,并从Employee Address实体反写映射

 class Employee
 {
    @Id
    private employee_id;

    private String employee_name;


    @OneToMany(mappedBy="department")
    private Set<EmployeeAddres> employeeAddress;



 }

和员工地址实体

 class EmployeeAddres
 {
      // add your other attributes (don't put employee_id attribute)

     @ManyToOne
     @JoinColumn(name="employee_id")
     private Employee employee;

 }