Using hibernate/hql to truncate a table?

后端 未结 6 1386
借酒劲吻你
借酒劲吻你 2020-12-29 06:45

What is the recommended way to truncate a table using hibernate/hql?

I\'ve tried this:

 Query query = session.createQuery(\"truncate table MyTable\");
 qu         


        
6条回答
  •  太阳男子
    2020-12-29 06:52

    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();
    }
    

提交回复
热议问题