Hibernate复合键与抽象类

时间:2014-04-24 00:42:06

标签: java hibernate

是否可以使具有复合主键(personID,部门名称)的Employee表保持

Person的类@id注释,同时保持它是一个抽象类。

public abstract class Person {
    @Id
    @GeneratedValue
    @Column(name = "PERSON_ID")
    private Long personId;

    @Column(name = "FIRSTNAME")
    private String firstname;


    // Getter and Setter methods, 
}



@Entity
@Table(name="EMPLOYEE")
@PrimaryKeyJoinColumn(name="PERSON_ID")
public class Employee extends Person {

    @Column(name="joining_date")
    private Date joiningDate;

    @Column(name="department_name")
    private String departmentName;

    public Employee() {
    }

    public Employee(String firstname, String lastname, String departmentName, Date joiningDate) {

        super(firstname, lastname);

        this.departmentName = departmentName;
        this.joiningDate = joiningDate;
    }

    // Getter and Setter methods, 
}

0 个答案:

没有答案