双向亲子关系

时间:2016-07-20 07:59:17

标签: java hibernate jpa

在这种情况下如何设计JPA双向重定向?

 Class Person{
       List<Person> relatedPersons;

       Person parentPerson;

    }

我尝试下一步,但接收递归。

  Class Person{
           @OneToMany(mappedBy = "parentPerson")
           List<Person> relatedPersons;

           @ManyToOne
           @JoinTable(joinColumns = {@JoinColumn(name = "related_person_id", referencedColumnName = "id") 
           Person parentPerson;

        }

1 个答案:

答案 0 :(得分:0)

试试这个:

Class Person{
       @OneToMany (mappedBy = "parentPerson")
       List<Person> relatedPersons;

       @ManyToOne
       @JoinColumn(name="PARENT_PERSON_ID")
       Person parentPerson;
    }