-->
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.  [ 1 post ] 
Author Message
 Post subject: Wrong Order By gets applied first, Criteria vs. Annotation
PostPosted: Thu Aug 09, 2007 2:26 pm 
Newbie

Joined: Thu Aug 09, 2007 2:11 pm
Posts: 1
Location: Sacramento, Ca
The problem I am having is that I have a class A that has a Set of class B (Needs to be a Set, not a List). I need the Set of class B to always be loaded ordered by B.name ascending. I have the following annotations in class A to accomplish this:


Code:
Class A{

@OneToMany(mappedBy="itemA", fetch=FetchType.EAGER)
@OrderBy("name")
private Set<B> itemBs = new HashSet<B>();

...
}


However, when I perform a search for A's in the database, I need my list of results to come back ordered by A.name. Instead they are coming back ordered by B.name and then A.name. My search method looks like this:

Code:
private Criteria buildSearchCriteria(SearchCommand command)
{

Criteria crit = getSession().createCriteria(A.class);

....//Build search parameters, add restrictions to criteria

crit = crit.addOrder(Order.asc("name").ignoreCase());
return crit;
}


I am wondering if there is a way to tell Hibernate to apply the Criteria Order By clause before the Annotation Order By clause?

Or any other suggestions would be much appreciated.

Thanks! :)


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

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.