0

in @inheritance type Joined

I have class person, employee and Student

i have common columns in Person , and getters setters for discriminator column if i have to access it from person class

@Inheritance(strategy=InheritanceType.JOINED) @DiscriminatorColumn(name="PERSON_TYPE", discriminatorType=DiscriminatorType.STRING) public class Person

@Column(name = "RELATIONSHIP_TYPE",insertable=false,nullable=false,updatable=false) private String relationType;

// getters and setters

@DiscriminatorValue("STUDENT") @PrimaryKeyJoinColumn(name="PERSON_ID") public class Student

@DiscriminatorValue("EMPLOYEE") @PrimaryKeyJoinColumn(name="PERSON_ID") public class Employee

so when i am saving the Employee or Student record and then retrieving Person record, It is giving me discriminator column value as NULL but after restarting the server its giving me value accordingly

if i manually set the value of discriminator column value and then save and retrieve then its giving me the value (Do i need to manaully set the discriminator column value?) then what is benefit of using discriminator column

why should i not use OneToMany relation of person with employee and student having column Type and via enum i can enter the perspective value into the column and i will also apply lazy fetching on that columns

Please Suggest

Thanks In Advance Ramandeep Singh

4

1 回答 1

0

我有相同的用例,但做了一点不同。我有一个枚举 PersonType 和一个在每个扩展类中都被覆盖的抽象属性。Hibernate 使用鉴别器来决定创建哪个类,并且类决定哪个是鉴别器值,既作为映射又作为属性。

pubilc abstract PersonType getType();
于 2012-08-23T10:19:23.827 回答