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.  [ 1 post ] 
Author Message
 Post subject: Sort a collection with columns of another table
PostPosted: Mon Aug 27, 2007 9:32 am 
Beginner
Beginner

Joined: Tue May 17, 2005 2:48 pm
Posts: 47
Hibernate version: 1.2.0

Mapping documents:
<class name="SalesManager" table="SalesManager" lazy="false" >
<id name="ID" column="ID">
<generator class="identity" />
</id>

...

<bag name="Clients" table="Clients" inverse="true" order-by="City, Street" >
<key column="SalesManagerID" />
<one-to-many class="Client" />
</bag>
</class>

Name and version of the database you are using:
SQL Server 2005

The generated SQL (show_sql=true):
SELECT salesman0_.ID as ID__1_,
address1_.City as Address0_0_, address1_.Street as Street0_0_
FROM SalesManager salesman0_
left outer join Address address1_ on salesman0_.AddressID=address1_.ID
WHERE salesman0_.ID=?
ORDER BY salesman0_.City, salesman0_.Street] ---> System.Data.SqlClient.SqlException: Invalid column name 'City'.


I want to order a collection. The columns I want to order on are not in table Client but in table Address. The table Client is joined with table Address. Can I specify this in my mapping file?
I could sort the collection using a comparer, but I'm wondering if it also can be done in the order by attribute of a bag in my mapping file.


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

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.