-->
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.  [ 7 posts ] 
Author Message
 Post subject: How to empty a big table ?
PostPosted: Thu Sep 11, 2003 11:40 pm 
Regular
Regular

Joined: Wed Sep 03, 2003 8:04 am
Posts: 55
There is a log table in MySQL which needs to be cleared now.However i am not sure how to empty it using hql ?

Of cource it is not applicable to load and delete record one by one.Do i need to use sql instead of hql ?


BTW,
i am using hibernate-2.0.2.


thanks in advance !


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 11, 2003 11:44 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Yes, just use some direct SQL.


Top
 Profile  
 
 Post subject: thanks......
PostPosted: Thu Sep 11, 2003 11:54 pm 
Regular
Regular

Joined: Wed Sep 03, 2003 8:04 am
Posts: 55
[quote="gavin"]Yes, just use some direct SQL.[/quote]


would you like showing me how to use direct sql in hibernate ? i really donot want to do as below:
...
sess.connection().createStatement()....

because this way will force me to be table-oriented NOT object-oriented :(


regards!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 12, 2003 12:05 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
But hold on: you just expressed your problem as "empty a table" ..... so it is a table-oriented problem, right?


;-)


This is the only way to do it.


Top
 Profile  
 
 Post subject: maybe i can regard it as a flexible feature ?
PostPosted: Fri Sep 12, 2003 12:32 am 
Regular
Regular

Joined: Wed Sep 03, 2003 8:04 am
Posts: 55
public void clearLog() throws OMException
{
try {
Session sess = sf.openSession(); sess.connection().createStatement().execute("delete from log");

sess.close();
}
catch(Exception e) {
throw new OMException(e);
}
}

the code is very simple but the programmer must know the table name,log.

Anyway i can accept it even if i am a pure OO fan :)


thanks !


Top
 Profile  
 
 Post subject: Re: maybe i can regard it as a flexible feature ?
PostPosted: Fri Sep 12, 2003 12:39 am 
Pro
Pro

Joined: Tue Aug 26, 2003 8:07 pm
Posts: 229
Location: Brisbane, Australia
midas wrote:
sess.connection().createStatement().execute("delete from log");


Given that you're wanting to do a "delete" not a DB specific "truncate" or anything like that, couldn't you just do the following?
Code:
sess.delete("from <pkg>.Entity as E");


Of course, I've not actually ever done that myself, but it would work wouldn't it?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 12, 2003 12:43 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Nah, stolley, that actually loads up each object, since it needs to process cascades, collections, lifecycle callbacks, etc.


One of these days, I might get round to providing an efficient implementation in the case where none of these things exist (thats the only reason i havn't deprecated the method). But last time I thought about it there were conceptual issues....


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