views:

314

answers:

1

Hi,
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 order-by from .hbm and just use the one mentioned in Criteria api.

+1  A: 

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.

CrazyPheel
Yes, thats what i saw Criteria has addOrder and not setOrder.Also i checked on the hibernate forums and it seems to be a bug in Hibernate3.Using HQL the bug might go away as was mentioned in those forums.But is there a way using the Criteria API itself or in the HBM file using some filter (I tried using that but got bad SQL grammer exceptions)
Rajat