There are three tables A and B1 and B2:
A(id, b_id, control)
B1(id, other)
B2(id, other)
If control = 1, b_id in A is mapping to table B1;
If control = 2, b_id in A is mapping to table B2.
These three classes is like:
@Entity
@Table(name = "A")
public class A {
@Id
@Column(name = "id")
private Integer id;
private B b;
@Column(name = "control")
private Integer control;
}
@Entity
@Table(name = "B1")
public class B1 {
@Id
@Column(name = "id")
private Integer id;
@Column(name = "other")
private Integer other;
}
Class B2 is almost same with B1.
I need get different object B from table B1 or B2 determined by field control
in class A. Is it possible to make it with hibernate annotation?
Appreciated for any advice.