Hi, I would like to use a feature of Hibernate 2 (2.0.3) in Hibernate 3.
In Hibernate 2, I could delete a batch of record by passing a String in the session.delete. Like:
Code:
session.delete(SQL String).
It seems that now in hibernate3 this feature is not there anymore. How can we delete all record from a table?
I would need this feature for my initializing my UnitTest...
Must I do a "from mytable" iterate in it and delete each Object??
According to the PDF documentation of Hibernate 3, the function is not there anymore:
HIBERNATE 2.0.3 PDFCode:
7.6. Deleting persistent objects
Session.delete() will remove an object's state from the database. Of course, your application might still hold
a reference to it. So it's best to think of delete() as making a persistent instance transient.
sess.delete(cat);
---------> You may also delete many objects at once by passing a Hibernate query string to delete().
You may now delete objects in any order you like, without risk of foreign key constraint violations. Of course,
it is still possible to violate a NOT NULL constraint on a foreign key column by deleting objects in the wrong order.
HIBERNATE 3 PDF:Code:
10.8. Deleting persistent objects
Session.delete() will remove an object's state from the database. Of course, your application might still hold
a reference to a deleted object. It's best to think of delete() as making a persistent instance transient.
sess.delete(cat);
You may delete objects in any order you like, 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.
Thanks
Etienne
Montreal