如何在hibernate映射中进行order-by [英] how to do order-by in hibernate mapping

查看:693
本文介绍了如何在hibernate映射中进行order-by的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设对象A有一个对象B的列表,并且对象B必须有一个对象C,B可以是基于C.level的命令。



在A. hbm.xml
$ b

 < bag name =listB
table =T_B
inverse = false
order-by =我应该在这里做什么???
>
< key column =ID_Anot-null =true/>
< / bag>


解决方案

order-by子句应该包含SQL代码段将用于订购物品清单。如果您的示例中您的订购条件不在T_B表中,那么您可能无法完成您想要的任务。另一方面,如果B包含一个C,并且它始终是一对一的关系,那么可以在DB中定义一个视图来聚合这些表,并为您提供一个可以排序的列。


suppose Object A has a list of Object B, and Object B must have a object C, B can be order base on C.level .

In A.hbm.xml

<bag name="listB"
             table="T_B"
             inverse="false"
             order-by="?? what should i do here???"
         >
            <key column="ID_A" not-null="true"/>
            <many-to-many column="ID_B" class="B"/>
        </bag>

解决方案

The order-by clause should contain the SQL snippet you would use to order the list of items. If your ordering criteria is not located in the table T_B in your example, then you probably won't be able to accomplish what you want. On the other hand if B contains a C and its always a one to one relationship, you could define a view in the DB the aggregates the tables and gives you a column to sort on.

这篇关于如何在hibernate映射中进行order-by的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆