I have a Person table which has two columns: first_name and last_name. The Person class has two corresponding fields: firstName and lastName. Now I'm using criteria api and trying to create an order by based on these two columns concatenated. Is it possible? Or it can only be achieved by hql?
Order by orders the data on the basis of given property in ascending or descending order. Group by groups the data on the basis of given property. In HQL we perform order by and group by for the given property of entity or associated entities.
uniqueResult() Convenience method to return a single instance that matches the query, or null if the query returns no results.
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.
Here an example for the JBoss hibernate site:
from DomesticCat cat order by cat.name asc, cat.weight desc, cat.birthdate
Or from the same website, for the Criteria api:
List cats = sess.createCriteria(Cat.class)
.add( Restrictions.like("name", "F%")
.addOrder( Order.asc("name") )
.addOrder( Order.desc("age") )
.setMaxResults(50)
.list();
They seem to be quite fond of cats at JBoss.
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