开发者

JPA map relation entity parentID

开发者 https://www.devze.com 2022-12-28 13:15 出处:网络
could someone help me to understand how can I define an entity with JPA mapping that has a relation with it self?

could someone help me to understand how can I define an entity with JPA mapping that has a relation with it self?

For example, my en开发者_JS百科tity is CompanyDivision, divisionA contains divisionB, divisionC and divisionB contains divisionB1, divisionB2

  • divisionA
    • divisionB
      • divisionB1
      • divisionB2
    • divisionC

Thank you!


It's not different from a relation between 2 different Entities. Here's an example:

class CompanyDivision {

    @OneToMany(mappedBy = "parentDivision")
    private Set<CompanyDivision> childDivisions = new HashSet<CompanyDivision>();

    @ManyToOne
    @JoinColumn(name = "FK_PARENT_DIVISION")
    private CompanyDivision parentDivision;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消