File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark ""Removing a detached instance" exception while updating the entity" Watch ""Removing a detached instance" exception while updating the entity" New topic
Author

"Removing a detached instance" exception while updating the entity

Ismael Upright
Ranch Hand

Joined: Feb 15, 2007
Posts: 166
...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

Joined: Feb 15, 2007
Posts: 166
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

Joined: Feb 15, 2007
Posts: 166
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: "Removing a detached instance" exception while updating the entity
 
Similar Threads
Bidirectional @OneToOne with JoinTable
'new' operator vs updating database
detached entity passed to persist
Searching row in database by a column which is not a primary key
Not-unique unique column