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)
Matt
  • 9,068
  • 12
  • 64
  • 84
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,161
  • 4
  • 16
  • 30
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,823
  • 15
  • 18
0

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

Sascha
  • 1