-->
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.  [ 2 posts ] 
Author Message
 Post subject: Sort after adding object to a collection
PostPosted: Fri Jun 08, 2007 12:11 pm 
Newbie

Joined: Tue Dec 06, 2005 10:13 am
Posts: 17
Hi,

I am adding an object to a child collection (Set) and then I save the object. For example:

parent.getChilds().add(someChild);

I want that the child collection will be sorted according to the "sort-by" property. Currently the object is added to the end of the list and only after opening a new session it is sorted properly. How this can be accomplished in Hibernate?

Thanks.


Top
 Profile  
 
 Post subject: Maybe this can help ...
PostPosted: Fri Jun 08, 2007 12:37 pm 
Newbie

Joined: Tue Jun 05, 2007 10:54 am
Posts: 3
Location: Brasil
Bashan, in my project, we used a (Query) Filter , after we add all the elements to the collections. Something like this :

public Collection filtrarColecao(Collection collection, String hql) {
Query filterQuery = sessao.createFilter(collection, hql);
return filterQuery.list();
}

But note that this method returns a Collection, with the order set by the HQL String.

Something like :

if(_cli.getChas() != null && _cli.getChas().size() > 0) {
ArrayList chasOrdenadosDesc = (ArrayList)repositorio.filtrarColecao(_cli.getChas(), "order by datCha desc");

}


Hope this can help you.

_________________
Eduardo Carneiro


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.