-->
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.  [ 8 posts ] 
Author Message
 Post subject: order persistence collections
PostPosted: Tue Dec 28, 2004 7:45 am 
Regular
Regular

Joined: Tue Oct 12, 2004 9:02 am
Posts: 66
Location: Italy
I have a user which have many items.
So user have a collection:
user.getItems();

and i want to order items owned by user at runtime.
How to modify this collection?
filter are not good for that :
session.filter(user.getItems(), "...").list();
return another collection instead of change the user property in place.

How to achieve that?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 28, 2004 8:50 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
why aren't collection filters good for that ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 28, 2004 8:57 am 
Regular
Regular

Joined: Tue Oct 12, 2004 9:02 am
Posts: 66
Location: Italy
max wrote:
why aren't collection filters good for that ?


I read in Hibernate in Action that "Hibernate collection filters are not executed in memory" and it does an example where if the collection in not initialized the filter will not initialize it. So i thought the filter returns another collection and do not change the collection owned by the entity...is it right?
for example:

List results = session.createFilter( item.getBids(),
"order by this.amount asc" ).list();

now i thought that item.getBids() is not ordered...am i wrong?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 28, 2004 9:00 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
The filter returns not the original collection, this is in the next paragraph in HiA. Read on :)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 28, 2004 9:01 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
And: surely touching the original collection would be wrong. How could Hibernate order your Set, for example? Yes, the name "filter" is not really good.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 28, 2004 9:08 am 
Regular
Regular

Joined: Tue Oct 12, 2004 9:02 am
Posts: 66
Location: Italy
christian wrote:
And: surely touching the original collection would be wrong. How could Hibernate order your Set, for example? Yes, the name "filter" is not really good.


Adding an order by clause somewhere for example (there the possibility to add an order by in the mapping file fo example, but not on the fly)...it would be useful in my opinion.
I try to examplain...ok this feature is not necessary, but i think it would be really useful in MVC pattern.
I pass the bean with the collection to the presentation layer (JSP), and there i iterate on its collection to show all the items owned by the entity.

If i want to change something in the order for example I can't use the collection from the bean, and I have to store the filtered collection in my controller (servlet for example) in a request or session attribute. And it is less elegant maybe.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 28, 2004 9:15 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
It's quite simple:

a) your collection only has a few elements, then it could be sorted in memory by you just fine

b) your collection is huge, then you definitely want lazy loading and explicit setFirst/setMaxResult with a setFilter() for presentation purposes

Everything else is a weird hack (Max opened a feature request for "smart" collections), but its not nice. Other ORM tools do that, because they don't have Bags and Filters.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 28, 2004 9:18 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
If order means something to you then use a sorted set or a list.

Or have a comparator you can use to extract the order you want...or have a collection that delagtes add/removes to the beans collection when you add/remove from it in the presentation.

_________________
Max
Don't forget to rate


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