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

  • Post author:
  • Post category:Bugs
  • Post comments:0 Comments
  • Post last modified:November 7, 2021
  • Reading time:1 mins read

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