Why do I have to persist both objects if Address is nested in User?

后端 未结 3 1298
无人共我
无人共我 2021-02-09 05:54

I am trying to better familiarize myself with JPA so I created a very simple project. I have a User Class and an Address class. It appears that I have to persist both even tho

3条回答
  •  醉话见心
    2021-02-09 06:31

    You are using a oneToMany annotation. From my understanding you have to persist the parent class (the USer) when you want to add a child class (Address) to it.

    By persisting the User class, you do let know JPA know which row to update.

提交回复
热议问题