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?

1 Answer 1

4

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?

Sign up to request clarification or add additional context in comments.

2 Comments

Ehy thank's it worked! (but i had to use setParameterList instead the simple setParameter). However it's solved now, thx ^^
Thanks! Improved my answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.