Hibernate: ORDER BY using Criteria API.

Ads

 
 

Share on Google+Share on Google+

ratna rathor
Hibernate: ORDER BY using Criteria API.
1 Answer(s)      5 years and 3 months ago
Posted in : Hibernate

How to display record in order using Criteria API?

Ads
View Answers

May 29, 2012 at 6:51 PM


Hibernate Criteria API provides an easy way of building dynamic query on the persistence database.

The hibernate criteria API is very Simplified API for fetching data from Criterion objects. The criteria API is an alternative of HQL (Hibernate Query Language) queries. It is more powerful and flexible for writing tricky criteria functions and dynamic queries.

You can easily order your record by using Criteria API either in ascending order or in descending order.

Example- In ascending order-

Session session = sessionFactory.openSession();

        Criteria criteria = session.createCriteria(Employee.class);
        criteria.addOrder(Order.asc("name"));

In descending order-

Criteria criteria = session.createCriteria(Employee.class);
        criteria.addOrder(Order.desc("name"));

Ads









Related Tutorials/Questions & Answers:
Hibernate: ORDER BY using Criteria API.
Hibernate: ORDER BY using Criteria API.  How to display record in order using Criteria API?   Hibernate Criteria API provides an easy way.... You can easily order your record by using Criteria API either in ascending order
Retrieve data using Criteria api
Retrieve data using Criteria api  import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Query; import...=configuration.buildSessionFactory(); Session s=sf.openSession(); Criteria criteria
Advertisements
criteria api
criteria api  what is the purpose of Restrictions class   Using Restrictions class, we can narrow the result of our query.Here are some restrictions that can also be use to narrow our Criteria query result
What is criteria API?
What is criteria API?  Hi, What is criteria API? Thanks,  ... on the persistence database. The hibernate criteria API is very Simplified API for fetching data from Criterion objects. The Hibernate Criteria API contains Restriction class
Hibernate Criteria API
criteria functions and dynamic queries. Using Criteria API to create...Hibernate Criteria API The API (Application Programming Interface... on the persistence database. The hibernate criteria API is very Simplified API for fetching
Using criteria for multiple tables
Using criteria for multiple tables  How to join more than three tables,those tables must be maintain primary key relation ship using Hql criteria & projections
Using criteria for multiple tables
Using criteria for multiple tables  How to join more than three tables,those tables must be maintain primary key relation ship using Hql criteria & projections
Using sum() in hibernate criteria.
Using sum() in hibernate criteria.  How to calculate sum() in hibernate criteria by using projection?   You can calculate sum of any numeric value in hibernate criteria by using projection. Projection is an interface
Hibernate criteria query using Max()
Hibernate criteria query using Max()  What is Hibernate criteria query using Max()?   You can find out maximum value in hibernate criteria... in ?org.hibernate.criterion?. For using Projection object in our Criteria, we have to call
Hibernate criteria query using Min().
Hibernate criteria query using Min().  How to find minimum value in Hibernate criteria query using Projection?   You can find out minimum value in hibernate criteria by using projection. Projection is an interface
Hibernate criteria query using avg()
Hibernate criteria query using avg()  How to calculate average in Hibernate criteria query using Projection?   You can calculate average of any numeric values in hibernate criteria by using projection. Projection
Hibernate criteria example using struts2
Hibernate criteria example using struts2 This hibernate criteria example using... API is used for creating dynamic query. With the help of criteria, you can create query without HQL. In this hibernate criteria example using struts2, we
Joining tables using criteria
Joining tables using criteria  How do i join more than three tables and retrieve one column from parent table and count of unique values in a single column from child table,the joined tables must be maintain primary key
Case-insensitive ordering using Hibernate Criteria.
Case-insensitive ordering using Hibernate Criteria.  What is Case-insensitive ordering in Hibernate Criteria
Case-sensitive equals using Hibernate Criteria.
Case-sensitive equals using Hibernate Criteria.  How to check for case sensitive equals in Hibernate criteria?   package net.roseindia.main... : 220000 Date of Join : 2001-02-03 00:00:00.0 Description : Hibernate Criteria API
Hibernate Criteria
the different ways of using the Criteria Query. The Hibernate Criteria API...Hibernate Criteria - Learn the Hibernate Criteria API and master the Hibernate framework The Hibernate Criteria query API is used to selectively find
criteria
criteria  Hi how to find highest salary of an employee using criteria in hibernate?   Here is a code that finds the maximum salary among the employees from the database using Hibernate Criteria. Criteria criteria
Case-insensitive equals using Hibernate Criteria.
Case-insensitive equals using Hibernate Criteria.  How to use Case-insensitive equals with Hibernate Criteria?   The Case Insensitive... = sessionFactory.openSession(); Criteria criteria = session.createCriteria
How to get unique list in Hibernate using Criteria Query?
How to get unique list in Hibernate using Criteria Query?  Hi, Share me the example code for getting Unique List in Hibernate through Criteria Query? Thanks
Hibernate Criteria :Ordering the results
In this section, you will learn about ordering the results using Hibernate Criteria query
Hibernate Detached Criteria Subquery
In this section we will discuss how to write subqueries using Detached Criteria in Hibernate
uSING JAVA API
uSING JAVA API  How to extract Quickbooks online data using Quickbooks api( Rest ApI) write in java code ? 1.register company account 2..register application 3.get apptoken,consumer key,consumer screte 4.how can i
Hibernate Criteria Examples
of using Hibernate Criteria query. With the help of criteria query you can... Hibernate Criteria NotEqual Example Hibernate Criteria Hibernate Criteria API... Hibernate Criteria Join Hibernate Criteria And Or Hibernate Criteria Order
Hibernate Criteria Distinct
from the student table. The same thing can be written using Criteria distinct API as follows Criteria criteria = session.createCriteria(Student.class...Hibernate Criteria Distinct The Hibernate Criteria Distinct API search
Examples of Hibernate Criteria Query
Criteria Order by Hibernate Criteria hibernate criteria Distinct Hibernate... Not In Hibernate Criteria Not Like Hibernate Criteria API Hibernate Criteria... Sort Order Hibernate criteria setFirstResult. Hibernate criteria setMaxResult
Hibernate Criteria Query Example Program
Example program? Explain me he Criteria Query API. Thanks   In the Hibernate Criteria Query Example You will find the source code of using Criteria...Hibernate Criteria Query Example Program  Hi, I am new in Hibernate
Hibernate Criteria average example
of the Hibernate Criteria API which is used to find the average, maximum or minimum values... how to find the average using the Criteria Query. Read more Hibernate...Hibernate Criteria average example - Learn how to perform Hibernate Criteria
gmail access using javamail API
gmail access using javamail API  how to coonect to gmail using java mail API ?  Hi Friend, Please visit the following link: http://www.roseindia.net/javamail/ Hope that it will be helpful for you. Thanks   
Hibernate Criteria Order by
Hibernate Criteria API Order By The Order By API of hibernate criteria is used to display the results either in ascending or descending order. Suppose you...(); An Example of Criteria order by is given below OrderByExample.java package
Criteria in Hibernate
Criteria in Hibernate  What is Criteria in Hibernate?   Criteria is a simplified API for retrieving entities by composing Criterion objects. This is a very convenient approach for functionality like "search" screens
Hibernate criteria by id.
Hibernate criteria by id.  How to display record by using criteria by id in Hibernate