【发布时间】:2013-06-05 22:05:35
【问题描述】:
sessionFactory.getCurrentSession().createQuery(
"delete from Attendance attend where attend.id in(Select att.id from Attendance att where att.dat= :dat and att.cls_id= :cls_id)"
).setDate("dat", dat).setShort("cls_id",cls_id); // delete all records with matching date and cls_id
sessionFactory.getCurrentSession().flush();
sessionFactory.getCurrentSession().clear();
// immediate save after delete in same transaction
for(Attendance a : absent){
sessionFactory.getCurrentSession().save(a);
}
我正在尝试删除具有特定条件的现有行,因为我正在保存的对象可能已经存在于表中。但是该删除不起作用,并且正在插入重复的值。请让我知道代码的哪一部分是错误的。
【问题讨论】:
-
为什么会有这么复杂的查询,而不仅仅是
delete from Attendance att where att.dat= :dat and att.cls_id= :cls_id? -
我改变了它并在它不起作用时变得复杂,这是我的愚蠢错误,可能是我太困而忘记执行了。对不起各位,非常感谢你们。
标签: java hibernate spring-mvc hql