为什么在Hibernate 5中不推荐使用条件查询? [英] Why is criteria query deprecated in Hibernate 5?

查看:704
本文介绍了为什么在Hibernate 5中不推荐使用条件查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如我们所知,标准查询 Hibernate 5 中已弃用。它在以前版本的Hibernate中是如此有用的功能。 它仍然比HQL表现更好。

As we already know, criterion query is 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 中弃用它的原因是什么?

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

此问题也不是这个问题因为我想知道标准查询弃用的原因。

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

这是来自这里。


Hibernate提供较旧的遗留 org.hibernate.Criteria API,其中
应被视为已弃用。没有功能开发将针对这些API的
。最终,Hibernate特定的标准功能将被
移植为JPA
javax.persistence.criteria.CriteriaQuery 的扩展。有关
org.hibernate.Criteria API的详细信息,请参阅Legacy Hibernate Criteria Queries。

Hibernate offers an older, legacy org.hibernate.Criteria API 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.Criteria API, see Legacy Hibernate Criteria Queries.


推荐答案

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

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

考虑一下:

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

与评论相反,我们打算继续提供特定于Hibernate的功能功能,但我们希望通过标准API引入这些功能,而不是尝试管理两个非常不同的API,这些API应该是同步互补的。

Contrary to comments, we do intend 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 5中不推荐使用条件查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆