Hibernate 5 query deprecated

In Hibernate 5 query has been deprecated, in this article we are teaching you how to use query in Hibernate?

Ads

Hibernate 5 query deprecated - What is latest method of running query in Hibernate 5?

In Hibernate 5 query has been deprecated and developer should learn new method of running query in Hibernate 5. Hibernate 5 comes with many changes and way to running query is deprecated. In this tutorial we will learn new method of running query in Hibernate 5.

In the previous versions of Hibernate we were using the method session.createQuery(QUERY)  to create Query object. 

We were using following code in previous version of Hibernate:

String SQL_QUERY ="from Employee obj";
Query query = session.createQuery(SQL_QUERY);

In Hibernate 5 we may use following code:

CriteriaQuery cq = session.getCriteriaBuilder().createQuery(Employee.class);
cq.from(Employee.class);
List employeeList = session.createQuery(cq).getResultList();

for (Employee employee : employeeList) {
	System.out.println("ID: " + employee.getId());
	System.out.println("Name: " + employee.getEmpName());
} 

Here in Hibernate 5 we can use CriteriaBuilder to create CriteriaQuery and use this to create query and run the getResultList() method to get data from database.

This is one of the latest way of getting data in Hibernate 5. You should check complete example code at Hibernate 5 Annotation Example tutorial page.

Check more tutorials of Hibernate 5.

Advertisements

Share on Google+Share on Google+

Hibernate 5 query deprecated

Posted on: July 25, 2017 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

 

Discuss: Hibernate 5 query deprecated  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0

Ads

 

Ads