 |
|
 |
 |
|
 |
 |
| Author |
Message |
|
|
Post subject: Sort Order in Hibernate
Posted: Nov 10, 2006 - 03:54 PM
|
|
Veteran Member


Joined: Nov 10, 2006
Posts: 3
|
|
I've used MyEclipse to reverse engineed hibernate mappings for my database. When I walk through the Set of objects that are gathered from the foreign key relation, they return in a different and unpredictable order each time. How do I sort the items so that they show up in the same order every time?
| Code: |
<hibernate-mapping>
<class name="AdminProfile" table="admin_profile" catalog="enterprise">
<id name="adminId" type="java.lang.Integer">
<column name="admin_id" />
<generator class="increment" />
</id>
...
<set name="divisionAdmins" inverse="true">
<key>
<column name="admin_id" not-null="true" />
</key>
<one-to-many class="DivisionAdmin" />
</set>
</hibernate-mapping>
<hibernate-mapping>
<class name="DivisionAdmin" table="division_admin" catalog="enterprise">
<composite-id name="id" class="DivisionAdminId">
<key-many-to-one name="adminProfile" class="AdminProfile">
<column name="admin_id" />
</key-many-to-one>
<key-many-to-one name="division" class="Division">
<column name="division_id" />
</key-many-to-one>
</composite-id>
</class>
</hibernate-mapping>
<!-- The primary key for the above DivisionAdmin contains an AdminId and DivisionId, referencing each table -->
<hibernate-mapping>
<class name="Division" table="division" catalog="enterprise">
<id name="divisionId" type="java.lang.Integer">
<column name="division_id" />
<generator class="increment" />
</id>
...
<set name="divisionAdmins" inverse="true">
<key>
<column name="division_id" not-null="true" />
</key>
<one-to-many class="DivisionAdmin" />
</set>
</class>
</hibernate-mapping>
|
When I did the Hibernate reverse-engineering, each object contains a set of the objects.
AdminProfile
Set divisionAdmins
DivisionAdmin
Division division
Basically, I want to be able to iterate through these and for a given AdminProfile, list all Divisions in the right order.
| Code: |
<c:forEach items="${admin.divisionAdmins }" var="divisionAdmin">
<c:set var="division" value="${divisionAdmin.id.division }" />
<li>${division.name } is id # ${division.divisionId}</li>
</c:forEach>
|
How do I control the sorting order? |
|
|
| |
|
|
|
 |
|
|
Post subject:
Posted: Nov 10, 2006 - 04:51 PM
|
|
Moderator


Joined: Feb 03, 2006
Posts: 1117
|
|
costlow,
You have to use order-by attribute in set element, for example :
| Quote: | <set name="divisionAdmins" inverse="true" order-by="your_properties_fromDivisionAdmin asc|desc">
<key>
<column name="division_id" not-null="true" />
</key>
<one-to-many class="DivisionAdmin" />
</set> |
MyEclipse doesn't support order-by in Reverse Engineering and you have to edit your mapping file
Regards, |
_________________ Peco
MyEclipse Support
Please do us a big favor and remember to vote for MyEclipse at the JDJ Reader's Choice Awards.
We really appreciate it!
|
| |
|
|
|
 |
|
|
| |
|
|
 |
|
 |
|
|
|
 |