hibernate 中根据id删除一条记录的语句

时间:2023-03-09 14:39:34
hibernate 中根据id删除一条记录的语句
qid name like content
1 A 1 the first text
2 B 2 the Second text
1 C 3 the Third text

如上表所示,当我们需要某个qid执行删除操作时,可以按照如下语句进行执行

         String hql="from bbsLikes  b where b.qid=(:ID)";
String[] paramName={"ID"};
Object[] value={qid}; List list = this.getHibernateTemplate().findByNamedParam(hql, paramName, value);
if(!list.isEmpty()){
this.getHibernateTemplate().deleteAll(list);
return true;
}
return false;
}