HQL删除查询和session.delete()之间的区别
我对 Hibernate 很陌生,有一个问题。使用 HQL 查询删除对象与使用 Session
类的 delete(...)
方法删除对象有什么区别?
I'm quite new to Hibernate and have a question. What is the difference between deleting an object by using an HQL query and deleting an object by using the delete(...)
Method of the Session
Class?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Session.delete(...)
仅当您已经拥有对要删除的实体的引用时才有用。delete-by-query 对于根据特定条件删除多个对象(您之前可能未加载到会话中的对象)非常有用。
我相信按查询删除实际上将每个实体加载到会话中并单独删除它们 - 如果我在这一点上错了,有人会纠正我。
Session.delete(...)
is only useful if you already have a reference to the entity you want to delete.delete-by-query is useful for deleting several objects according to certain criteria, objects that you may not have previously loaded into the session.
I believe that delete-by-query actually loads each entity into the session and deletes them individually - someone correct me if I'm wrong on this.