JPA EntityManager: Why use persist() over merge()?

后端 未结 15 1617
说谎
说谎 2020-11-22 03:09

EntityManager.merge() can insert new objects and update existing ones.

Why would one want to use persist() (which can only create new objec

15条回答
  •  梦如初夏
    2020-11-22 03:26

    Going through the answers there are some details missing regarding `Cascade' and id generation. See question

    Also, it is worth mentioning that you can have separate Cascade annotations for merging and persisting: Cascade.MERGE and Cascade.PERSIST which will be treated according to the used method.

    The spec is your friend ;)

提交回复
热议问题