I am trying to retrieve the rows in a db using hibernate criteria.
I want to get entries with null values for column in the end using Hibernate Criteria . For example, if the entries are appearing in the DB as follows for column:
Column
______
"AB"
NULL
"DC"
NULL
"DG"
Then after using Hibernate criteria I should get:
Column
_____
"AB"
"DC"
"DG"
NULL
NULL
Is there any way or workaround to achieve this? I am newbie to hibernate. Any help will be appreciable.
Heading
您可以使用order by对值进行排序。
criteria.addOrder(Order.asc(FIELD_NAME));
There is a 7 year old (!) unresolved issue: HHH-465: order by nulls first / last .
54 people voting and my favourite comment:
Emmanuel Bernard added a comment - 08/Sep/06 11:07 AM
"We are working on a large project using Hibernate, and really would like to see this issue fixed."
So either provide a patch or consider commercial support
The optional "nulls first" or "nulls last" may do the trick.
For example:- Select foo from Foo foo order by foo.id asc, foo.field2 desc nulls first, foo.field3
The optional nulls first or nulls last indicate precedence of null values while sorting.
Please check the following link
http://docs.jboss.org/hibernate/orm/4.2/manual/en-US/html/ch16.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.