views:

17

answers:

1

I want to retrieve a collection property using criteria

   public class A {  
       private Collection<B> property  
       // getters and setters
   }  
   public class B {
      private int status
      // getters and setters
   }

My criteria code is as follows:

Criteria cr = getSession().createCriteria(A.class)     
cr.createAlias("property", "prop")
cr.add(Restrictions.eq("prop.status", status));
cr.setProjection(Projections.property("prop"));
cr.list();

It's obvious this code doesn't work I wanted to simply demonstrate my intentions. I know how to achieve this using HQL, but I have to use Criteria API. Is what I am aiming for even possible using Criteria ?

Thanks, Peter

A: 

What wrong with this solution ?

Criteria cr = getSession().createCriteria(B.class);
 cr.add(Restrictions.eq("status", status));
 cr.list(); 
Vash
I need A.property collection not just all B instances in the DB with a certain status. I need all B connected to A with a provided status. Unfortunately B has no references to A (I wouldn't have ask a question if that were the case), just the A 0..* B connectionRegards,Peter
pmanolov