5

How can I write an HQL query like same SQL query like this:

select * from Users u where u.id in (1, 3, 4)
Matthew
  • 7,831
  • 11
  • 56
  • 80
Andre
  • 79
  • 1
  • 3
  • 6
  • Maybe this will help you: http://stackoverflow.com/questions/961816/proper-way-of-writing-a-hql-in-query Another example using JPA: http://stackoverflow.com/questions/4828049/in-clause-in-hql-or-java-persistence-query-language I've never used hql, but it always help to google a bit :) – Steven Apr 06 '11 at 06:56

3 Answers3

0

I suggest you use native query to utilize your SQL query, so that you don't have to convert to HQL.

Thang Nguyen
  • 1,163
  • 4
  • 16
  • 28
0

The simplest way to do this with play is

public static void findByIds(List<Long> userIds) {
    find("from Users u where u.id in (?1)", userIds).fetch();
}
Seb Cesbron
  • 3,759
  • 13
  • 17
0

Try User.find("id in (:ids)").bind("ids", new Long[]{1L,3L,4L}).fetch()

Sascha
  • 1