hibernate and delete all

前端 未结 3 1534
悲&欢浪女
悲&欢浪女 2021-02-01 02:31

What is the best way to delete all rows in a table in Hibernate?

If I iterate over a collection and call session.delete() it\'s not perform

3条回答
  •  暖寄归人
    2021-02-01 03:28

    You can use HQL for truncate table

    public int hqlTruncate(String myTable){
        String hql = String.format("delete from %s",myTable);
        Query query = session.createQuery(hql)
        return query.executeUpdate();
    }
    

提交回复
热议问题