"org.hibernate.HibernateException: instance was not in a valid state" in Hibernate
Issue
- Migrating from Hibernate 3 / EAP 5
- During a transaction an entity referenced by an association is removed/deleted
- Cascade.ALL or Cascade.REFRESH was specified for the association
-
When calling EntityManager.refresh(Object) on the (valid) entity associated with the removed/deleted entity an exception is raised:
... org.hibernate.HibernateException: instance was not in a valid state at org.hibernate.engine.spi.EntityEntry.isReadOnly(EntityEntry.java:367) at org.hibernate.event.internal.DefaultRefreshEventListener.onRefresh(DefaultRefreshEventListener.java:153) at org.hibernate.internal.SessionImpl.fireRefresh(SessionImpl.java:1108) at org.hibernate.internal.SessionImpl.refresh(SessionImpl.java:1092) at org.hibernate.engine.spi.CascadingAction$3.cascade(CascadingAction.java:204) at org.hibernate.engine.internal.Cascade.cascadeToOne(Cascade.java:396) at org.hibernate.engine.internal.Cascade.cascadeAssociation(Cascade.java:339) ... at org.hibernate.engine.internal.Cascade.cascade(Cascade.java:164) at org.hibernate.event.internal.DefaultRefreshEventListener.onRefresh(DefaultRefreshEventListener.java:122) ... at org.hibernate.internal.SessionImpl.refresh(SessionImpl.java:1071) at org.hibernate.ejb.AbstractEntityManagerImpl.refresh(AbstractEntityManagerImpl.java:942) ...
Environment
- Red Hat JBoss Enterprise Application Platform (EAP)
- 7
- 6
- Hibernate
- 5
- 4
- JPA 2.x
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase of over 48,000 articles and solutions.
Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.
