我有两个实体
@Entity
class A {
@Id
private Long Id;
//attributes of A
}
@Entity
class B {
xxx
private A instanceOfA_1;
xxx
private A instanceOfA_2;
}
如您所见,我在 B 类中有两个 A 类型的属性。
您将如何在 Hibernate 中注释这两个属性?最后,在数据库中,我希望在表 B 中找到两列,每一列都包含表 A 中的键 id。
我想这是一个简单的 ORM 问题,但我没有设法单独解决它......
编辑:在上述回复之后,您建议我执行以下操作?
@Entity
class A {
@Id
private Long Id;
//attributes of A
}
@Entity
class B {
@ManyToOne
private A instanceOfA_1;
@ManyToOne
private A instanceOfA_2;
}
这将创建以下表格?
Table A
id
attributes
Table B
a_id_1
a_id_2
如何指定表 B 中的列名(即 a_id_1 和 a_id_2)?