[solved] caused by: org.hibernate.PersistentObjectException: detached entity passed to persist:

The error looks like

org.hibernate.PersistentObjectException: detached entity passed to persist: example.forms.InvoiceItem     
    at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:127) 
    at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:799)     
    at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:791)     
    .... (truncated)

Solution

This exists in @ManyToOne and @ManytoMany relation. I solved this issue by just using CascadeType.MERGE instead of CascadeType.PERSIST or CascadeType.ALL.

Hope it helps you.

Leave a Reply