我有一个包含以下字段的人员表:
id,name,parent_id。
parent_id实际上是列ID的FK。 数据应该像这样(像金字塔一样):
"id" "name" "parent_id"
"1" "I am the Top Father" "1"
"2" "My Father Is 1" "1"
"3" "My Father Is 2" "2"
"4" "My Father Is 2" "2"
我的豆子看起来怎么样?
由于
答案 0 :(得分:4)
@Entity
@Table(name="persons")
public class Person {
@Id
private Long id;
private String name;
@ManyToOne
@JoinColumn(name="parent_id")
private Person parent;
...
}