how to do order-by in hibernate mapping

。_饼干妹妹 提交于 2019-12-11 04:56:17

问题


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>

回答1:


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.




回答2:


I though order-by is specified in your query? no?

exp:

from Document fetch all properties order by name


来源:https://stackoverflow.com/questions/1366197/how-to-do-order-by-in-hibernate-mapping

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!