"java.lang.IllegalArgumentException: Removing a detached instance" in Hibernate

Solution Verified - Updated -

Issue

When EntityManager.remove(...) is called for an entity an exception like the below is raised:

    ... java.lang.IllegalArgumentException: Removing a detached instance org.test.SomeEntity#00000005
        at org.hibernate.event.internal.DefaultDeleteEventListener.disallowDeletionOfDetached(DefaultDeleteEventListener.java:196)
        at org.hibernate.event.internal.DefaultDeleteEventListener.performDetachedEntityDeletionCheck(DefaultDeleteEventListener.java:184)
        at org.hibernate.event.internal.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:105)
        at org.hibernate.event.internal.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:72)
        at org.hibernate.internal.SessionImpl.fireDelete(SessionImpl.java:1015)
        at org.hibernate.internal.SessionImpl.delete(SessionImpl.java:951)
        at org.hibernate.internal.SessionImpl.remove(SessionImpl.java:3461)
        at org.jboss.as.jpa.container.AbstractEntityManager.remove(AbstractEntityManager.java:655)
    ...

Environment

  • Red Hat JBoss Enterprise Application Platform (EAP) 7
  • Hibernate 5
  • Seam (obsolete)

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content