使用hibernate / hql截断表? [英] Using hibernate/hql to truncate a table?
本文介绍了使用hibernate / hql截断表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试过这个:
使用hibernate / hql截断表的推荐方式是什么?
查询查询= session.createQuery(truncate table MyTable);
query.executeUpdate();
但它不起作用(truncate似乎没有记录在hql的任何地方......)
解决方案
我猜这样做的一个可怕的方式是删除所有。
public int hqlTruncate(String myTable){
String hql = String.format(delete from%s,myTable);
Query query = session.createQuery(hql);
返回query.executeUpdate();
}
What is the recommended way to truncate a table using hibernate/hql?
I've tried this:
Query query = session.createQuery("truncate table MyTable"); query.executeUpdate();
But it didn't work (truncate doesn't seem do be documented anywhere in hql...)
解决方案
I guess an horrible way of doing it would be deleting all.
public int hqlTruncate(String myTable){
String hql = String.format("delete from %s",myTable);
Query query = session.createQuery(hql);
return query.executeUpdate();
}
这篇关于使用hibernate / hql截断表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文