-->
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: Sort With Column And List Mapping
PostPosted: Wed Jul 26, 2006 1:31 pm 
Beginner
Beginner

Joined: Thu Dec 15, 2005 12:02 pm
Posts: 23
I have two tables. Both tables are entities. (see below)
Anyway, I have a one-to-many from att_option_group to att_option.
There si a sort_order on the att_option table. When I retrieve the current set of att_option objects, I would like to be able to put them into a list in order by the sort_order. Then I could shuffle the List, and persist the data again, changing the sort order dynamically. I do not want to do an order_by clause. I would like hibernate to understand the sort_order and be able to shuffle the List.

Here is my current map from att_option_group to att_option.

<set name="options" cascade="all" lazy="false" inverse="false">
<key column="att_opt_grp_id" />
<one-to-many class="com.mb.purcell.model.AttOptions" />
</set>

Could someone please .. help me with this.

Scott



mysql> select * from att_option_group
-> ;
+----------------+------------------+------------+
| att_opt_grp_id | att_opt_grp_name | sort_order |
+----------------+------------------+------------+
| 1 | Stories | 1 |
| 2 | Baths | 2 |
+----------------+------------------+------------+
2 rows in set (0.17 sec)

mysql> select * from att_option;
+------------+----------------+------------+---------------+
| att_opt_id | att_opt_grp_id | sort_order | att_opt_value |
+------------+----------------+------------+---------------+
| 1 | 1 | 1 | 1 |
| 2 | 1 | 2 | 1.5 |
| 3 | 1 | 3 | 2 |
| 4 | 2 | 1 | 2 |
| 5 | 2 | 2 | 2.5 |
| 6 | 2 | 3 | 3 |
+------------+----------------+------------+---------------+
6 rows in set (0.09 sec)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 26, 2006 3:19 pm 
Expert
Expert

Joined: Tue Apr 25, 2006 12:04 pm
Posts: 260
I am not sure how you exactly want a solution. In case if below scenario helps... you can try it in your implementation

Code:
//------------
// you have already accessed AttOptionGroup object
// and now want to sort the children( i.e. options ) on some property
//------------
AttOptionGroup group = getGroup();// previously retrieved object

Session session = getSession();
List optionsList = session.createFilter( group.getOptions(), " order by this.sortOrder " ).list();


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.