Home  >  Forum  >  Hibernate
Post New Query

org.hibernate.PersistentObjectException: detached entity passed to persist



Asked on November 22, 2015
I am inserting row in MySQL database using Spring and hibernate. I am getting the following error. Any clue?

Caused by: org.hibernate.PersistentObjectException: detached entity passed to persist: 
at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:139)
at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:75)
at org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:811)
at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:784)
at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:789)
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:1181)




Replied on November 22, 2015
Check in your code that if you have used 

@GeneratedValue(strategy=GenerationType.AUTO)

and at the same time you are inserting id (any primary key value) by code too.
Do not insert id by code if using @GeneratedValue


Write Answer







©2019 concretepage.com | Privacy Policy | Contact Us