-->
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.  [ 4 posts ] 
Author Message
 Post subject: order-by column for Set mapping
PostPosted: Wed Dec 01, 2004 6:00 pm 
Newbie

Joined: Mon Aug 30, 2004 5:15 pm
Posts: 13
I am trying to order a set by a property of the child object. Whenever I do this, the sql generated thinks that the order-by property belongs to the parent object and not the child.

The main object is called Split and contains a set of Regions. I am trying to order the set of regions in Split by the property Regions.name. The mapping is:

<class name="Split" table="split">
...
<set name="regions" lazy="true" cascade="none" table="split_region" order-by="name_region">
<key column="id_split"/>
<many-to-many class="com.pga.matrix.geo.Region" column="id_region"/>
</set>
</class>

<class name="Region" table="geo_region">
<id name="id" type="int">
<column name="id_region"/>
<generator class="native"/>
</id>
<property name="name" column="name_region" type="string" not-null="true" length="50"/>
</class>

The generated SQL (show_sql=true):

Hibernate: select regions0_.id_split as id_split__, regions0_.id_region as id_region__, region1_.id_region as id_region0_, region1_.name_region as name_reg2_0_, region1_.shortname_region as shortnam3_0_, region1_.region_number as region_n4_0_ from split_region regions0_ inner join geo_region region1_ on regions0_.id_region=region1_.id_region where regions0_.id_split=? order by regions0_.name_region


Hibernate version: 2.1.6

How can I get the order-by clause to work correctly? The correct sql in the snippet above should be "... order by region1_.name_region".


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 01, 2004 7:39 pm 
Regular
Regular

Joined: Sun Aug 01, 2004 6:49 pm
Posts: 76
As far as I remember the only way for this would be a custom Comparator class which you have to implement by your own. Use then the sort attribute for your set. Example:
Code:
<set name="mySet" lazy="true"
   inverse="true" cascade="all-delete-orphan"
   sort="my.MyComparator">
[...]
</set>


HTH
Thomas


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 16, 2004 8:15 am 
Newbie

Joined: Wed Sep 01, 2004 5:31 am
Posts: 18
See:

http://forum.hibernate.org/viewtopic.ph ... ny+orderby

This is what you want to do right?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 16, 2004 10:02 am 
Newbie

Joined: Mon Aug 30, 2004 5:15 pm
Posts: 13
That answers my question. It isn't currently supported.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.