Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is criteria query deprecated in Hibernate 5?

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 JPA javax.persistence.criteria.CriteriaQuery. For details on the org.hibernate.Criteria API, see Legacy Hibernate Criteria Queries.

like image 784
Pritam Banerjee Avatar asked Jul 19 '16 01:07

Pritam Banerjee


People also ask

Why Hibernate Criteria API deprecated?

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.

Is hibernate criteria deprecated?

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.

What is the advantage of criteria query compared with HQL or SQL?

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.

What is Criteria query in hibernate?

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.


1 Answers

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.

like image 131
Naros Avatar answered Oct 22 '22 02:10

Naros