i am using hibernate3
from my mapping file :
Code:
<set name="paragraphs"
table="article_paragraph"
cascade="all"
order-by="weight asc"
>
<key column="articleid"/>
<many-to-many
column="paragraphid"
class="my.package.Paragraph"
/>
</set>
weight is a property of a Paragraph bean.
the sql that gets generated:
Code:
select
paragraphs0_.articleid as articleid1_,
paragraphs0_.paragraphid as paragrap2_1_,
paragraph1_.id as id0_,
paragraph1_.paragraph as paragraph4_0_,
paragraph1_.type as type4_0_,
paragraph1_.weight as weight4_0_,
paragraph1_.binaryid as binaryid4_0_
from
article_paragraph paragraphs0_
inner join paragraphs paragraph1_ on paragraphs0_.paragraphid=paragraph1_.id where paragraphs0_.articleid=1
order by paragraphs0_.weight asc
it is trying to find the weight column on the article_paragraph table
while i would want it to get it on the paragraphs table like this: ( i changed the above sql to the code i want -- only changed the last line)
Code:
select
paragraphs0_.articleid as articleid1_,
paragraphs0_.paragraphid as paragrap2_1_,
paragraph1_.id as id0_,
paragraph1_.paragraph as paragraph4_0_,
paragraph1_.type as type4_0_,
paragraph1_.weight as weight4_0_,
paragraph1_.binaryid as binaryid4_0_
from
article_paragraph paragraphs0_
inner join paragraphs paragraph1_ on paragraphs0_.paragraphid=paragraph1_.id where paragraphs0_.articleid=1
order by paragraph1_.weight asc
am i wrong somewhere oris there really no way to do this with order-by ?
i know i can do it with "sort" and a comparator but i would like the db to do the sorting instead of having it done in memory.