-->
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.  [ 3 posts ] 
Author Message
 Post subject: Order By when Eager Fetching a 1:M relationship
PostPosted: Mon Jun 12, 2006 12:46 pm 
Senior
Senior

Joined: Sat Sep 10, 2005 3:46 pm
Posts: 178
I am trying to order a collection that I am eagerly fetching but cannot seem to come up with the correct criteria call. I have speciefied that the collection should be ordered in the mapping but that seems to get discarded if I do an Eager fetch.

Here is the mapping

Code:
<bag name="SubSteps" table="Step"  access="field.camelcase-underscore" lazy="true"
         cascade="all-delete-orphan" inverse="true" order-by="Sequence asc">


Here is the current code that ignores the order by in the mapping:

Code:
ICriteria criteriaQuery = this.Session.CreateCriteria(typeof(RootStep));
criteriaQuery.Add(Expression.Eq("Procedure", this.Procedure));
criteriaQuery.AddOrder(Order.Asc("Sequence"));
criteriaQuery.SetFetchMode("SubSteps", FetchMode.Eager);
criteriaQuery.SetResultTransformer(CriteriaUtil.DistinctRootEntity);



I have an order by sequence set for the root step list but I also need the substeps ordered.

I have tried to specify subcriteria and order the collection that way but I get an exception that states that subcriteria cannot be ordered.

I would appreciate any advice on this.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 14, 2006 10:45 am 
Senior
Senior

Joined: Sat Sep 10, 2005 3:46 pm
Posts: 178
Should I just do this with HQL? I'd prefer to use the criteria query, but if nobody has any input, then I guess HQL will do the job. It just seems that there may be a bug if the order-by of the mapping file is getting ignored.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 14, 2006 12:22 pm 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
sorry, i never saw the original post. you cannot (yet) order by a subcriteria. i agree that the mapping file should still apply when doing an eager fetch but i too have noticed that it doesn't. perhaps you can make an enhancement request?


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

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.