-->
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 do I delete an entire table?
PostPosted: Mon Dec 15, 2003 2:25 pm 
Newbie

Joined: Wed Dec 10, 2003 3:55 pm
Posts: 9
Location: Atlanta, GA
How can I do something like:
"delete from shopping_cart"

Where I can just do a single database call to delete everything?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 15, 2003 2:32 pm 
Newbie

Joined: Fri Oct 31, 2003 9:17 am
Posts: 10
Location: USA
Hi,

You could get the connection object from your session, and execute your delete statement.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 15, 2003 2:38 pm 
Newbie

Joined: Wed Dec 10, 2003 3:55 pm
Posts: 9
Location: Atlanta, GA
I was looking at the code of Session.delete(query). And it seems like it first queries all the objects that match the query, then individually deletes each object. I have a rather large table, and I'd rather not delete each row individually.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 15, 2003 4:49 pm 
Newbie

Joined: Fri Oct 31, 2003 9:17 am
Posts: 10
Location: USA
Hi,

You could do something like this:

Code:
try {
    Connection conn = session.connection();   
    Statement stmt = conn.createStatement();
    stmt.execute("delete from myTable");
} catch (SQLException se) {
    ...
}


hope this helps


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 15, 2003 5:14 pm 
Newbie

Joined: Wed Dec 10, 2003 3:55 pm
Posts: 9
Location: Atlanta, GA
I guess I might have to resort to doing it this way since I don't see a way in Hibernate to do it.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 16, 2003 5:09 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Hibernate have to load your objects first for many reasons includiong cascade stuff etc...
The best solution for you is to use plain JDBC

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 16, 2003 9:31 am 
Newbie

Joined: Wed Dec 10, 2003 3:55 pm
Posts: 9
Location: Atlanta, GA
Alright, thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 17, 2003 1:21 am 
Expert
Expert

Joined: Fri Nov 07, 2003 4:24 am
Posts: 315
Location: Cape Town, South Africa
session.createSQLQuery() ?


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.