-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Page 411 about deleting detached object
PostPosted: Mon Feb 09, 2009 7:20 am 
Beginner
Beginner

Joined: Sat Feb 07, 2009 12:31 am
Posts: 21
It says:

Quote:
This means you don’t have to reattach (with update() or lock()) a detached instance to delete it from the database. In this case, the call to delete() does two things: It reattaches the object to the Session and then schedules the object for deletion, executed on tx.commit(). The state of the object after the delete() call is removed.


But if you do just that, you'll get an exception like this:

java.lang.IllegalArgumentException: Removing a detached instance com.samples.Blabla
at org.hibernate.ejb.event.EJB3DeleteEventListener.performDetachedEntityDeletionCheck(EJB3DeleteEventListener.java:47)
at org.hibernate.event.def.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:86)
at org.hibernate.event.def.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:52)
at org.hibernate.impl.SessionImpl.fireDelete(SessionImpl.java:766)
at org.hibernate.impl.SessionImpl.delete(SessionImpl.java:744)
Code:
      Session s =
      ((HibernateEntityManager)
         DataSrc.getHibEntityMF().createEntityManager())
         .getSession();
      
      s.beginTransaction();
      
      s.delete(myBlablaObj);
      
      s.getTransaction().commit();



Hibernate 3.3.1.GA
Hibernate Annotations 3.4.0.GA
Hibernate Entity Manager 3.4.0.GA


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 10, 2009 10:48 am 
Beginner
Beginner

Joined: Sat Feb 07, 2009 12:31 am
Posts: 21
Sorry.

The exception is misleading, though I have figured out what I was doing wrong, I was trying to delete a transient object. The book explains how to delete a detached object and not about how to delete a transient object.

The exception must have said "deleting a transient instance" instead of "deleting a detached instance".


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.