0

How to express such HQL query via criteria API?

select a from A a where
(select b.prop from B b where b.id = a.parent) in ('1', '2', '3')

List of ids is passed as parameter.

Here is my subquery:

DetachedCriteria subQuery = DetachedCriteria.forClass(B.class, "b").
                .add(Restrictions.eqProperty("b.id", "a.parent"))
                .setProjection(Projections.property("b.prop"));

Subqueries.in and propertyIn work the opposite way (prop in subquery, not subquery in prop as i need). Any thoughts?

SpyBot
  • 487
  • 2
  • 6
  • 16

1 Answers1

1

You can use Restrictions.in(...).

List<Integer> values=new ArrayList<Integer>();
values.add(1);
values.add(2);
values.add(3);

DetachedCriteria subQuery = DetachedCriteria.forClass(B.class, "b").
            .add(Restrictions.eqProperty("b.id", "a.parent"))
            .setProjection(Projections.property("b.prop")).
            .add(Restrictions.in("b.prop", values);
Genzotto
  • 1,954
  • 6
  • 26
  • 45