Hibernate/JPA ManyToOne vs OneToMany

后端 未结 4 601
粉色の甜心
粉色の甜心 2020-11-30 19:47

I am reading currently the documentation of Hibernate regarding the entity associations and I come accross a little difficulty to figure out some things. It has to do in ess

4条回答
  •  庸人自扰
    2020-11-30 20:06

    While above answers are accurate, I will present the answer in a different way.

    Both @OneToMany and @ManyToOne have two parts; left part and right part. For example; @OneToMany = 'One' is left part and 'Many' is right part likewise @ManyToOne = 'Many' is left part and 'One' is right part.

    Simple rule of association using this understanding is, left part represents the class that you are defining the association.

    So, if you define @ManyToOne in OrderLine class referencing to Order class, it means many OrderLine associated to one Order class.

提交回复
热议问题