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