Java 为什么 Hibernate 5 中不推荐使用标准查询?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38448195/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 20:20:46  来源:igfitidea点击:

Why is criteria query deprecated in Hibernate 5?

javahibernatehibernate-criteria

提问by Pritam Banerjee

As we already know, criterion queryis deprecated in Hibernate 5. It was such a useful feature in the previous versions of Hibernate. And it still performs better than HQL.

正如我们已经知道的,标准查询Hibernate 5 中已被弃用。在以前的 Hibernate 版本中,这是一个非常有用的功能。而且它的性能仍然比 HQL 好。

So what is the reason of it's deprecation in Hibernate 5?

那么它在Hibernate 5 中被弃用的原因是什么?

And also this question is not a duplicate of this questionas I want to know the reason of the deprecation of criteria query.

而且这个问题不是一个重复这个问题,因为我想知道标准查询弃用的原因。

This is from here.

这是从这里。

Hibernate offers an older, legacy org.hibernate.CriteriaAPI which should be considered deprecated. No feature development will target those APIs. Eventually, Hibernate-specific criteria features will be ported as extensions to the JPA javax.persistence.criteria.CriteriaQuery. For details on the org.hibernate.CriteriaAPI, see Legacy Hibernate Criteria Queries.

Hibernate 提供了一个较旧的遗留org.hibernate.CriteriaAPI,应该被视为已弃用。任何功能开发都不会针对这些 API。最终,特定于 Hibernate 的标准特性将作为扩展移植到 JPA javax.persistence.criteria.CriteriaQuery。有关org.hibernate.CriteriaAPI 的详细信息 ,请参阅 Legacy Hibernate Criteria Queries。

采纳答案by Naros

We are deprecating the Criteria API in lieu of JPA extension support.

我们正在弃用 Criteria API 来代替 JPA 扩展支持。

Consider this:

考虑一下:

CriteriaBuilder cb = entityManager.getCriteriaBuilder();
HibernateCriteria hc = cb.unwrap( HibernateCriteria.class );
...
query.where( hc.someAwesomeThing( ... ) );
List<SomeEntity> entities = entityManager.createQuery( query ).getResultList();

Contrary to comments, we dointend to continue to deliver Hibernate-specific features, but we want to introduce those through the standard API instead rather than trying to manage keeping two very different APIs that are meant to be complementary in sync.

与评论相反,我们确实打算继续提供特定于 Hibernate 的功能,但我们希望通过标准 API 来介绍这些功能,而不是试图管理保持两个非常不同的 API 同步互补。