是否可以从 2 个可能的表中获取实体的字段?
例如:
@Entity
@Table(name = "TABLE_A")
public class A{
@Id
@Column(name = "ID")
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
}
@Entity
@Table(name = "TABLE_B")
public class B{
@Id
@Column(name = "ID")
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
}
@Entity
@Table(name = "TABLE_PARENT")
public class PARENT{
// This field needs to be fetched from A table or from B table!!! by some
// conditions
@OneToOne
@JoinColumn(name = "A_B_ID")
private A a;
}
Parent 类中的字段需要根据某些条件从 table_A 或 table_b 中获取!
任何想法将不胜感激!
澄清:如果 Parent 实际上指向 B 实例,我不想获取 B 的实例!每个类继承的表只在 A 的表中查找,因为我们在 Parent 类中指定了他的 A 类型字段!?
你有其他想法吗?