-->
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: Filter on value in a subcollection
PostPosted: Tue Jul 29, 2008 11:05 am 
Newbie

Joined: Tue Jul 29, 2008 10:53 am
Posts: 11
Let's say we have an Order and a Version.
Order is the main class, and every order has one or more versions:

Code:
Public class Order
{
   public Order()

   public virtual OrderCompany
   {
      get ...
      set ...
   }

   public virtual ISet Versions
   {
      get ...
      set ...
   }
}


I've mapped these classes and everything works perfectly.

Now I want to search for specific orders. If I search for orders from a company I use an expression:

LikeExpression LE = new LikeExpression("OrderCompany", "%CompanyX%");
This works very nice.

But now I would like to get only the orders that have a version 2: something like this:

EqExpression EE = new EqExpression("Versions.Number", "2");
But this doesn't work.

Anyone knows how to get what I want?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 29, 2008 11:33 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
You need a subcriteria:

Code:
ICriteria crit = session.CreateCriteria(typeof(Order),"o")
   .Add(Expression.Like("o.OrderCompany", "%CompanyX%))
   .CreateCriteria("o.Versions", "v")
       .Add(Expression.Eq("v.Version", "2"));

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 29, 2008 11:50 am 
Newbie

Joined: Tue Jul 29, 2008 10:53 am
Posts: 11
Thanks Wolli. That works prefectly!


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.