-->
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.  [ 4 posts ] 
Author Message
 Post subject: What's the best way to filter collections?
PostPosted: Thu Aug 26, 2004 9:50 pm 
Newbie

Joined: Tue Oct 28, 2003 6:00 pm
Posts: 14
Hibernate version: 2.1

Let's say I have an order with 100 line items and I want to display a single item in the order. I can use something like the following to get the subset of my line items,

lineItems = session.filter(order.getLineItems, "where this.itemNo=20")

However, the client code only retrieves line items via order.getLineItems() and is not aware of session. The LineItem is associated with Order via <set><one-to-many></set>. Can I use "where" in <set> where the criteria is given in runtime?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 27, 2004 8:14 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
No. In Hibernate3 you could use filters


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 27, 2004 2:18 pm 
Newbie

Joined: Tue Oct 28, 2003 6:00 pm
Posts: 14
michael wrote:
No. In Hibernate3 you could use filters


Since Hibernate3 is in alpha, I will stay with 2.1 for now. I found a solution for my problem, though not sure if it's the best one. Instead of mapping getLineItems() to LineItem, getLineItemsLazy() is used. The business method is defined as follows,


Code:
Order findOrder(long orderNo, int itemNo) {
  Order order = session.find.....
  if (itemNo == ALL_LINE_ITEMS) {
               Set set = order.getLineItemsLazy();
               set.size();
               order.setLineItems(set);
  } else {
      order.setLineItems(new HashSet(session.filter(order.getLineItemsLazy(), "where this.itemNo=" + itemNo)));
  }
  return order;
}


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 30, 2004 10:55 am 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
barryku, just so that you are aware by setting the new HashSet() you will lose the ability to have cascade delete work since the HashSet will not be keeping state like the persistent collections will.

I'm trying to tackle the same sort of problems on a grander and I had come up with a similar solution. In my case the cascade deletes aren't an issue but I think I have a few ideas to make it behave 'normally' when all is said and done.

I'm going to have to take another look at the filters but I'm not sure it's going to do the trick for me.


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