开发者

Problem with sorting on child object in Hibernate when order-by is present in .hbm files?

I am using Hibernate3.jar in our App.While trying to fetch some objects using the foreign key we used the order-by clause on the collection as shown below

< set name="children" cascade="all-delete-orphan" lazy="true" order-by="SORT_ORDER_ID asc,lower(CHILD_NAME) asc,lower(FIRST_NAME) asc,lower(LAST_NAME) asc">

Now i have a class where i am using the Criteria API and forcing to fetch the "children" objects using the join class i.e using fetch=join in the Criteria Api.But the problem comes when i try to put an orderby clause in Criteria api.It always seem to pick the order-by clause from the .hbm file (as shown in bold above) and appends my new orderby clause from the criteria api.Why does it append, why it doesnot ignore the 开发者_Go百科order-by from .hbm and just use the one mentioned in Criteria api.


Does this still happen if you write an HQL query, rather then using the Critiera class?

I wonder if since the Criteria API calls it "addOrder" rather then "setOrder", it just inherits the default order from the HBM file, and then "ADD" the order value to the defaults. But I don't know for certain, curious to find out if you still have that problem if you were to write an HQL query though.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜