10.7.2. Deleting Persistent Objects
Session.delete()
will remove an object's state from the database. Your application, however, can still hold a reference to a deleted object. It is best to think of delete()
as making a persistent instance, transient.
sess.delete(cat);
You can delete objects in any order, without risk of foreign key constraint violations. It is still possible to violate a
NOT NULL
constraint on a foreign key column by deleting objects in the wrong order, e.g. if you delete the parent, but forget to delete the children.