Saving modified existing object vs copy with modified fields

时间:2018-04-18 17:53:06

标签: java hibernate spring-data-jpa

I would like to ask for advice about Spring JPA and hibernate during modifying objects. Maybe it depends on design pattern or something.

There are two possibilities:

  1. Copy existing object (create new reference) modify and save copy as object.
  2. Modify existing object (without changing reference) and save.

Could you answer and explain why/when use which ?

1 个答案:

答案 0 :(得分:0)

JPA旨在以您描述为选项1的方式使用:

加载实体,修改它并(隐式地)在提交事务/会话时保存它。