-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Getting a sorted set back
PostPosted: Sun Jan 30, 2005 10:20 pm 
Beginner
Beginner

Joined: Sun Jan 09, 2005 5:16 pm
Posts: 20
Code:
<hibernate-mapping>
    <class name="org.appfuse.model.Category" table="CATEGORY">
        <id name="id" type="long" column="CATEGORY_ID">
            <generator class="increment"/>
        </id>
      <property name="name" type="string" column="CATEGORY_NAME" not-null="true"/>
      <list name="parents" table="CATEGORY_PARENTS">
         <key column="CATEGORY_ID"/>
         <index column="POSITION"/>
         <many-to-many class="org.appfuse.model.Category" column="PARENT_ID"/>
      </list>

      <set name="children" table="CATEGORY_CHILDREN">
         <key column="CATEGORY_ID"/>
         <many-to-many class="org.appfuse.model.Category" column="CHILD_ID"/>
      </set>
    </class>
</hibernate-mapping>


I'd like to be able to sort the set I get from getChildren() in ascending order based on Category.name. You're probably wondering why I wouldn't just make it a list, but this needs to be flexible, and I don't want to have to update the position column everytime we add a new category to make sure they're in alphabetical order. Is there a simple way to sort a set in hibernate?[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 30, 2005 10:32 pm 
Beginner
Beginner

Joined: Sun Jan 09, 2005 5:16 pm
Posts: 20
Nevermind, I wrote this helper class and added this to my mapping and it's working great

sort="org.appfuse.model.helper.CategoryComparator"


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.