Take the 2-minute tour ×

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"
             order-by="?? what should i do here???"
            <key column="ID_A" not-null="true"/>
            <many-to-many column="ID_B" class="B"/>
share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

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.

share|improve this answer
add comment

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


from Document fetch all properties order by name
share|improve this answer
thanks for you quick reply..but sometime query is not good enough....suppose i already got the object A...which is the Document object in your query...and i say...document.getProperties()....then the return value wouldn`t be in order –  shrimpy Sep 2 '09 at 7:11
Then I have to say sorry. I don't know how to set it either. I would use "Comparable" interface with "Collection.sort()" in this case, but this way I lose the beauty of query though. –  Winston Chen Sep 2 '09 at 7:37
add comment

Your Answer


