0

I have a very useful query in JPQL:

select count(p) from Project p, in (p.members) s where s.members.email = :email

or again

select p from Project p, in (p.members) s where s.members.email = :email order by p.lastUpdate desc

It is fast, easy to understand and works flawlessly. It even works great when the relationship is no a @*ToMany but a @ElementCollection.

Now I need to convert the in (p.members) s where s.members.email = :email to Criteria API so that I can replicate this pattern of query across many similar entities, or also add "orderBy" and other conditions programmatically and I'd rather not do it through String manipulation, I am familiar with the basic uses of Criteria API but I am by no way an expert.

I have tried the CriteriaBuilder.in(~) but it seems to be a totally different meaning ... or maybe I am using it wrong.

Could someone help?

I am using Hibernate 4.3.0 behind JPA 2.1 (in Play!Framework).

le-doude
  • 3,345
  • 2
  • 25
  • 55
  • 1
    According to the spec, `from Project p, in (p.members) s` is equivalent to `from Program p join p.members s`, so try using a join instead. – DannyMo Mar 28 '14 at 17:22
  • Thanks it did work. So no "look alike" in Criteria API? – le-doude Mar 30 '14 at 10:24
  • 1
    I'm not really sure. I'd be surprised if there wasn't an equivalent criteria expression, but I personally always use the join pattern. – DannyMo Mar 30 '14 at 18:29

0 Answers0