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.
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.
This is from here.
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 JPAjavax.persistence.criteria.CriteriaQuery
. For details on theorg.hibernate.Criteria
API, see 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.
Since Hibernate 5.2, the Hibernate Criteria API is deprecated, and new development is focused on the JPA Criteria API. We'll explore how to use Hibernate and JPA to build Criteria Queries.
In Hibernate, the Criteria API helps us build criteria query objects dynamically. Criteria is a another technique of data retrieval apart from HQL and native SQL queries. The primary advantage of the Criteria API is that it is intuitively designed to manipulate data without using any hard-coded SQL statements.
Hibernate provides alternate ways of manipulating objects and in turn data available in RDBMS tables. One of the methods is Criteria API, which allows you to build up a criteria query object programmatically where you can apply filtration rules and logical conditions.
We are deprecating the Criteria API in lieu of JPA extension support.
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 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With