-->
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.  [ 5 posts ] 
Author Message
 Post subject: How to delete all data records in the db effeciently?
PostPosted: Fri Aug 05, 2005 6:52 pm 
Newbie

Joined: Wed May 11, 2005 4:25 pm
Posts: 5
Location: San Jose, CA
Hi,

1.
Does any one know an efficient way to delete all data records of a table in the database efficiently by Hibernate 2.1.* and 3.*?

2. Does any one know an efficient way to copy all of the data records in a table to another table with the same table definition by Hibernate?


Sincerely,

Thomas


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 05, 2005 6:57 pm 
Regular
Regular

Joined: Wed May 11, 2005 11:57 pm
Posts: 80
First question is easy:

Code:
   public void testDeleteAll() {
      Session session = TestUtils.sessionFactory.openSession();
      Transaction tx = session.beginTransaction();
      int rowsDeleted = session.createQuery("DELETE FROM Instructor").executeUpdate();
      System.out.println( rowsDeleted + " were deleted." );
      tx.commit();
      session.close();
   }


I'll leave the second one to someone else...


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 06, 2005 12:18 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
1) If you can use trancate then its more efficent than delete, eg,
Native SQL
Code:
trancate Instructor;


2) I would lean toward native SQL for that solution as well.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 06, 2005 2:06 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
For #2, if the table already exists, you can use the HQL insert-select statement


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 06, 2005 1:47 pm 
Newbie

Joined: Mon Jul 25, 2005 12:59 pm
Posts: 13
For #2 consider java ETL open source tools:
http://www.manageability.org/blog/stuff ... e-etl/view
http://technology.amis.nl/blog/index.php?p=284


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