3

I have a List composed by Integer elements. I have to make a single query like this:

 From Table as t where t.id <> element1 AND t.id <> element2 AND ......

Someone can give me a tip how to set the input list? I have to set the single element or the entire list?

Paolo Forgia
  • 5,804
  • 7
  • 39
  • 55
Removed
  • 99
  • 3
  • 17

1 Answers1

3

Create Collection of Integers:

Collection<Integer> ints = new ArrayList<Integer>();
ints.add(1);
ints.add(2);
ints.add(3);

Set it as parameter:

Query q = entityManager.createQuery("FROM Table as t WHERE t.id NOT IN (:ints)");
q.setParameterList("ints", ints);

Relevant question: Hibernate HQL Query : How to set a Collection as a named parameter of a Query?

Community
  • 1
  • 1
Rudziankoŭ
  • 8,411
  • 10
  • 66
  • 146