Can I reference 2 different entities with same column in hibernate?

Viewed 109

In my database, I have a column called "specialist_id". Based on the value of another column in the same table, it is either the id of a user entity (references some user table), or it is the id of a specialist entity (references specialist table). My question is, how can I do this in hibernate mapping? For example, I want to do something like below.....Is it possible?

@ManyToOne(fetch = FetchType.LAZY)
@Fetch (FetchMode.SELECT)
@JoinColumn(name = "SPECIALIST_ID")
private ApplicationUser specialist;

@ManyToOne(fetch = FetchType.LAZY)
@Fetch (FetchMode.SELECT)
@JoinColumn(name = "SPECIALIST_ID")
private DivSpecialist divSpecialist;
0 Answers
Related