Spring-Data JPA: save new entity referencing existing one

前端 未结 3 1018
谎友^
谎友^ 2020-12-08 04:24

The question is basically the same as below one:

JPA cascade persist and references to detached entities throws PersistentObjectException. Why?

I\'m creating

3条回答
  •  离开以前
    2020-12-08 05:19

    I have the same problem with a @EmbeddedId and business data as part of the id.
    The only way to know if the entity is new is performing a (em.find(entity)==null)?em.persist(entity):em.merge(entity)

    but spring-data only provides save() method and there is no way to fill the Persistable.isNew() method with a find() method.

提交回复
热议问题