NOT FOUND

jakarta.persistence.EntityExistsException: detached entity passed to persist 본문

spring boot

jakarta.persistence.EntityExistsException: detached entity passed to persist

이종은 2025. 7. 3. 13:59

detached entity passed to persist: kr.co.infra.rdb.goal.entity.GoalEntity jakarta.persistence.EntityExistsException: detached entity passed to persist: kr.co.infra.rdb.goal.entity.GoalEntity at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:126) at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:167) at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:173) at org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:767) at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:745) at org.springfr...

 

아이디를 넣어서 생성하려고 할 때 나는 에러.

더 정확하게는 이미 식별자가 존재하는 엔티티를 persist 하려고 하면 나는 에러다.

 

persist()는 새로운 엔티티를 저장할 때 쓴다. (id가 없거나 영속성 컨텍스트에 없는 상태)

만약 id를 생성자에서 미리 넣고 저장하고 싶다면 merge()를 쓰면 된다.