Sorting in java is not the ideal way. There must be some way of getting this done in the mapping itslf. I am also facing the same issue. Can anyone one help us out.
Main Topics
Browse All TopicsHi I was wondering when you have a many to many relationship in Hibernate if you can still order by a column on one of the child table.
For example, I have a client obj that has a set of addresses. Client and address have a many to many relationship, addresses are mapped on the client like this
<set name="addresses" table="client_address" cascade="all-delete-orphan
<key column="client_id" not-null="true" />
<many-to-many class="model.Address" column="address_id" unique="true" />
</set>
The mapping uses a reference table that only contains columns client_id and address_id. If I want to order the collection of addresses on the client obj based on a particular column in the address table, what do I need to do? I tried to use just the column name but I get error like
Caused by: java.sql.SQLException: Unknown column 'addresses0_.col1' in 'order clause'
That's because it is looking for the column in the client_address reference table instead of the address table.
How can I tell hibernate to look for the column in the address table?
Thanks
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: girionisPosted on 2008-01-11 at 01:38:31ID: 20635088
Have a look here: http://www.hibernate.org/1 18.html#A7
If all else fails you might as well do the sorting in the Java code itself.