2012-04-23 135 views
3

在hibernate中,是否有可能將鑑別器作爲實體?例如,如果我將Department作爲子類,將ProcessingDepartment作爲基類& AdminDepartment &。 DepartmentType是鑑別器&是映射到DEPT_TYPE表的實體。Discriminator列映射爲實體Hibernate

回答

5

是的,這是可能的,但這種關係將是隻讀的:

@Entity @Inheritence(...) 
@DiscriminatorColumn(name = "DEPT_TYPE_ID") 
public class Department { 
    ... 
    @ManyToOne 
    @JoinColumn(name = "DEPT_TYPE_ID", insertable = false, updatable = false) 
    private DepartmentType deptType; 
    ... 
}