Spring-Data JPA: save new entity referencing existing one
The question is basically the same as below one: JPA cascade persist and references to detached entities throws PersistentObjectException. Why? I'm creating a new entity that references an existing, detached one. Now when I save this entity in my spring data repository an exception is thrown: org.springframework.dao.InvalidDataAccessApiUsageException: detached entity passed to persist if we look at the save() method in source code of spring data JPA we see: public <S extends T> S save(S entity) { if (entityInformation.isNew(entity)) { em.persist(entity); return entity; } else { return em.merge