-->
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.  [ 3 posts ] 
Author Message
 Post subject: Delete all rows from a table in Hibernate
PostPosted: Mon Aug 30, 2004 4:55 pm 
Newbie

Joined: Mon Aug 09, 2004 10:53 am
Posts: 19
Hibernate version: 2.1

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

Debug level Hibernate log excerpt:


What's the best way to truncate a table in Hibernate?
I tried to do a

session.delete("from tableName")

to delete all rows but that doesn't seem to work.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 30, 2004 4:59 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
By "tablename" do you mean the actual underlying table name? That's not the correct syntax; it should be session.delete("from MyClassName").

Note that this really does not truncate in the DB sense. It actually loads all the objects and then deletes them one-by-one.

If you really, truly want truncate semantics you'll have to do:
Code:
session.connection().createStatement("delete from TABLENAME");
...


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 30, 2004 5:00 pm 
Proxool Developer
Proxool Developer

Joined: Tue Aug 26, 2003 10:42 am
Posts: 373
Location: Belgium
See documentation


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.