Tag Archives: JPA Error

org.hibernate.PersistentObjectException: detached entity passed to persist encountered by jpa

org.hibernate.PersistentObjectException: detached entity passed to persist encountered by jpa

 

This happens because we have specified the generation strategy of the primary key in the entity class with JPA annotations. The primary key cannot be set. Once it is not empty or 0, it is considered to have been saved in the database. Once the persist() method is called, it will be thrown. The above exception

 Remove 0, as shown below: