JPA @OneToMany -> Parent - Child Reference (Foreign Key)

后端 未结 5 1799
太阳男子
太阳男子 2020-12-07 19:10

i have a Question about referencing ParentEntities from Child Entites ir If i have something like this:

Parent.java:

@Entity(name ="Parent")
         


        
5条回答
  •  有刺的猬
    2020-12-07 19:27

    Yes, that is the case. JPA does not keep care about consistency of your entity graph. Especially you have to set it to the owner side of bidirectional relationship (in your case to the parent attribute of Child).

    In JPA 2.0 specification this is said with following words:

    Note that it is the application that bears responsibility for maintaining the consistency of run- time relationships—for example, for insuring that the “one” and the “many” sides of a bidi- rectional relationship are consistent with one another when the application updates the relationship at runtime.

提交回复
热议问题