简体   繁体   English

Hibernate 5.x 中的 HQL 和 Criteria API 有什么区别?

[英]What is difference between HQL and Criteria API in Hibernate 5.x?

现在查看 Hibernate 5 支持更新和删除标准以及 HQL。

  1. HQL is to perform both select and non-select operations on the data, but Criteria is only for selecting the data, we cannot perform non-select operations using criteria HQL是对数据进行选择和非选择操作,但Criteria只是对数据进行选择,不能使用标准进行非选择操作
  2. HQL is suitable for executing Static Queries, where as Criteria is suitable for executing Dynamic Queries HQL 适用于执行静态查询,而 Criteria 适用于执行动态查询
  3. HQL doesn't support pagination concept, but we can achieve pagination with Criteria HQL 不支持分页概念,但我们可以通过 Criteria 实现分页
  4. Criteria used to take more time to execute then HQL过去,标准比 HQL 需要更多时间来执行
  5. With Criteria we are safe with SQL Injection because of its dynamic query generation but in HQL as your queries are either fixed or parametrized, there is no safe from SQL Injection.使用 Criteria,我们可以安全地使用 SQL 注入,因为它可以动态生成查询,但在 HQL 中,由于您的查询是固定的或参数化的,因此 SQL 注入没有安全性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM