简体   繁体   English

使用Hibernate Criteria从最后的NULL条目中获取条目

[英]Using Hibernate Criteria to get entries from with NULL entries in the last

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 . 我想最后使用Hibernate Criteria获取带有空值的条目。 For example, if the entries are appearing in the DB as follows for column: 例如,如果条目出现在DB中,则列如下:

Column
______
"AB" 
NULL  
"DC"
NULL
"DG"

Then after using Hibernate criteria I should get: 然后在使用Hibernate标准之后我应该得到:

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. 任何帮助都会很明显。


  1. Heading

    #

您可以使用order by对值进行排序。

criteria.addOrder(Order.asc(FIELD_NAME));

There is a 7 year old (!) unresolved issue: HHH-465: order by nulls first / last . 有一个7岁(!) 未解决的问题: HHH-465:第一个/最后一个按空格排序

54 people voting and my favourite comment: 54人投票和我最喜欢的评论:

Emmanuel Bernard added a comment - 08/Sep/06 11:07 AM Emmanuel Bernard添加了评论 - 08 / Sep / 06 11:07 AM

"We are working on a large project using Hibernate, and really would like to see this issue fixed." “我们正在使用Hibernate开发一个大型项目,我真的希望看到这个问题得到解决。”

So either provide a patch or consider commercial support 因此要么提供补丁,要么考虑商业支持

The optional "nulls first" or "nulls last" may do the trick. 可选的“nulls first”或“nulls last”可以解决问题。
For example:- Select foo from Foo foo order by foo.id asc, foo.field2 desc nulls first, foo.field3 例如: - 通过foo.id asc从Foo foo顺序选择foo,foo.field2 desc nulls first,foo.field3

The optional nulls first or nulls last indicate precedence of null values while sorting. 可选的nulls first或nulls last表示排序时空值的优先级。

Please check the following link 请检查以下链接
http://docs.jboss.org/hibernate/orm/4.2/manual/en-US/html/ch16.html http://docs.jboss.org/hibernate/orm/4.2/manual/en-US/html/ch16.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM