我知道我的标题不够清晰,但是我不知道如何用简洁的话语来解释我的问题。
我有两个类之间存在双向映射。其中之一是Image.class
:
@Entity
@Table(name = "image")
public class Image{
@Id
@Column(name = "id")
@GeneratedValue
Long id;
@OneToOne(targetEntity = Father.class)
@JoinColumn(referencedColumnName = "id", name="father")
@Size(min = 1, max = 11)
Father father;
}
以及 Father.class
:
class Father{
@Id
@Column(name = "id")
@GeneratedValue
Long id;
@OneToOne(mappedBy = "father")
Image pic;
}
现在,我想把
Image.class
作为其他类的字段来使用。假设我有 Mother.class
。 class Mother{
@Id
@Column(name = "id")
@GeneratedValue
Long id;
@OneToOne(mappedBy = "mother")
Image pic;
}
我的问题是:我应该如何编辑Image.class
的“映射”?
当然,Image.class
不能像Father father
一样拥有字段,因为在最后的场景中,Image.class
是Mother.class
的字段,而不是Father.class
的字段。
我记得有一种方法可以在单个表中保存可以由多个不同的Entities
映射的Entity
。我记得我需要在表中添加一个字段来区分Image.class
是与Father.class
还是Mother.class
“绑定”的。
我无法在互联网上找到那份文档。