-->
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.  [ 8 posts ] 
Author Message
 Post subject: How to delete all rows in a table?
PostPosted: Mon Nov 22, 2004 4:55 pm 
Pro
Pro

Joined: Fri Nov 19, 2004 5:52 pm
Posts: 232
Location: Chicago, IL
Hi. I'm using Hibernate 3.0alpha and I'm a new to using Hibernate in general. Please excuse me if this is a FAQ. I looked around and haven't been able to find the answer so far. I'm trying to figure out how to delete all rows in a table.

It appears that this can be done using org.hibernate.classic.Session.delete(String query) to do this, but, this method is deprecated. It says in the API specification to use createQuery() to do this, but, I don't know how.

The other question that I have is, how to delete a Collection of objects? Do I have to iterate through the Collection and call delete() for each object? I was thinking that maybe I could just do a query for all rows in the table and then do a List.clear() and maybe it would delete the rows automatically...


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 22, 2004 5:04 pm 
Pro
Pro

Joined: Fri Nov 19, 2004 5:52 pm
Posts: 232
Location: Chicago, IL
BTW, I know how to do it the following way, I just want to know to do it without having to revert to using SQL...

Session s = sf.openSession();
PreparedStatement ps = s.connection().prepareStatement("TRUNCATE TABLE project");
ps.executeUpdate();


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 22, 2004 7:24 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
createQuery().delete()


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 22, 2004 8:29 pm 
Pro
Pro

Joined: Fri Nov 19, 2004 5:52 pm
Posts: 232
Location: Chicago, IL
Thanks but I'm not able to find a Session.createQuery() method (no args) or a Query.delete() method. Maybe these are new and aren't in hibernate-3.0alpha?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 23, 2004 4:32 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Why are you using the alpha?

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 23, 2004 11:19 am 
Pro
Pro

Joined: Fri Nov 19, 2004 5:52 pm
Posts: 232
Location: Chicago, IL
Why not use the alpha?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 23, 2004 11:46 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Because you don't use testing versions of a software you'd like to learn?

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 23, 2004 12:07 pm 
Pro
Pro

Joined: Fri Nov 19, 2004 5:52 pm
Posts: 232
Location: Chicago, IL
The reason I'm using hibernate3 is because I want to get a heads up on how to do things in the new version. I've been using both hibernate2 and hibernate3 and I noticed that a lot of the APIs are deprecated in the new version, so, I'm glad that I decided to have a look at it.

BTW, you never answered the question at hand.


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