• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

"Removing a detached instance" exception while updating the entity

 
Ismael Upright
Ranch Hand
Posts: 166
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...so I have the following two entities:







As you can see, every Customer can have one or zero bank accounts.

And the problematic code: I have created a customer and assigned abank account to it. Now I want to remove the bank account first, update the customer, and then I want to change the customer name.




The first update is done without problem, but during the second one I get the exception:

java.lang.IllegalArgumentException: Removing a detached instance Customer#262144
at org.hibernate.ejb.event.EJB3DeleteEventListener.performDetachedEntityDeletionCheck(EJB3DeleteEventListener.java:65)
at org.hibernate.event.def.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:108)
at org.hibernate.impl.SessionImpl.fireDelete(SessionImpl.java:957)
at org.hibernate.impl.SessionImpl.delete(SessionImpl.java:940)
at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:258)
at org.hibernate.engine.Cascade.cascade(Cascade.java:161)
at org.hibernate.event.def.AbstractFlushingEventListener.cascadeOnFlush(AbstractFlushingEventListener.java:154)
at org.hibernate.event.def.AbstractFlushingEventListener.prepareEntityFlushes(AbstractFlushingEventListener.java:145)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:88)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1206)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:375)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137)
at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:76)
... 44 more


What am I doing wrong?
And more important: what can I do to fix it?
 
Ismael Upright
Ranch Hand
Posts: 166
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In case if you wonder what the customerService does: it only calls GeneralDAO, which goes as follows:




The exception is raised in line 14.
 
Ismael Upright
Ranch Hand
Posts: 166
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The solution was to revert the relation between Customer and CustomerBankAccount.







Why does it work with that change? No idea. I suspect that the entities are left in the cash and the database management works better with reversed relation.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic