Can someone please tell me if there is a way to delete all the records from a table in Hibernate. I am looking for the same effect that "delete from SOMETABLE" has in SQL.
This is a 'truncate' operation, and I'm not sure how you could call it since it's a statement, not a query. By that, I mean it doesn't return any records so I'm not sure how well the query produced by session.createQuery() would handle it.
Is this the intention of the delete function? If so how does one use it?
Session.delete(Object) deletes a specific object previously loaded.
Session.delete(String) and variants deletes objects matching some criteria. You might be able to pass through a null or empty string, but I suspect you'll need to come up with some bogus criteria like "id is not null" where "id" is the name of your primary key.
But this is a poor second choice - truncate is usually *far* more efficient than any delete clause since you don't have to parse the records and evaluate them for matching some criteria.
MyTable mt = new MyTable() ; try { session.delete(mt); }
That's definitely wrong.
Something on my wishlist although I know it breaks existing code is to have some empty interface for objects managed by Hibernate, e.g., the boringly predictable HibernatedObject. This would make it clear to casual users that, oh,
int delete(HibernatedObject object)
or
void load(HibernatedObject object, Serializable id)
refer to a particular type of object. When I, and I assume other people, see an "Object" we think it means that we can reasonably pass in any object whatsoever.
I suppose the next major revision could introduce the HibernatedObject interface, and retain the existing "object" API as a deprecated set of methods....
------------------------------------------------------- This SF.net email is sponsored by: SF.net Giveback Program. Does SourceForge.net help you be more productive? Does it help you create better code? SHARE THE LOVE, and help us help YOU! Click Here: http://sourceforge.net/donate/ _______________________________________________ hibernate-devel mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/hibernate-devel