Using hibernate/hql to truncate a table?

后端 未结 6 1385
借酒劲吻你
借酒劲吻你 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 07:07

    You can use session.createSQLQuery() instead:

    session.createSQLQuery("truncate table MyTable").executeUpdate();
    

    Needless to say, this is not ideal in terms of portability. It's probably a good idea to define this query in mapping and retrieve it in code as named query.

提交回复
热议问题