Different way to fetch an object from database in Hibernate?

We are using following way to fetch an object from database in Hibernate.

HQL :- Hibernate Query Language (HQL) uses class name instead of table name, and property names instead of column name. we can create a HQL query and get the object after executing the query.

				
					// Gel all Employee data from HQL
Query query = session.createQuery("from Employee");
				
			

Criteria API :- Hibernate Criteria API provides Projection that we can use for aggregate functions such as sum(), min(), max() etc. we can use Criteria API to create the search conditions for getting the objects from database.

				
					//Get with ID, creating new Criteria to remove all the settings
Criteria criteria = session.createCriteria(Employee.class);
criteria = session.createCriteria(Employee.class).add(Restrictions.eq("id", new Long(3)));
				
			

Native SQL :- For Hibernate Native SQL Query, we will be use Session.createSQLQuery(String query) to create the SQLQuery object and execute it. we can write native SQL query for a database and just execute it to get the data we want and convert it into desired object.

				
					//Get all Employees list without condition
SQLQuery query = session.createSQLQuery("select * from Employee");
List<object[]> rows = query.list();
				
			

Identifier :- We can use load() or get() method and pass the identifier like primary key to fetch an object from database.

				
					//Retrieve the object using the primary key
Employee emp = (Employee) session.get(Employee.class, 1L);