Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有以下 JPA 实体
具有以下属性的模块类
具有以下属性的人员类
现在我需要为 Person 创建以下关系
我不知道如何在它自己的类(Person -> Person)中创建关系。
欢迎大家提出意见。谢谢
你这样做就像你有两个不同类的实体一样:
@Entity public class Person { @ManyToOne Person supervisor; ... }
如果你想要它是双向的,那么你也可以完全按照你有两个不同类的实体来做:
@Entity public class Person { @ManyToOne Person supervisor; @OneToMany(mappedBy = "supervisor") Set<Person> supervised; }