Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
两种变体之间有什么区别:
1.
session.createQuery("delete from Vacancy where id = :id") .setInteger("id", vacancy.getId()).executeUpdate()
;
2.session.delete(vacancy);
session.delete(vacancy);
使用的优点session.delete是,如果关联映射为 ,它会级联到关联的实例cascade="delete"。
session.delete
cascade="delete"
但是如果您使用直接删除查询,则不会发生级联createQuery。
createQuery