TheRocinante
TheRocinante

Reputation: 4201

Hibernate HQL NOT IN clause doesn't seem to work

// a is some String and bList is some list of type ArrayList
String findQuery = "SELECT T FROM " + MyClass.class.getName() + " T where a = :itemA and (b NOT IN (:bList))";
Query query = factory.getCurrentSession().createQuery(findQuery);
query.setParameter("itemA", a);
query.setParameter("bList", bList);

This is the query I am executing. Instead of giving me results where a = itemA and b is not in bList, it gives me results where a = itemA and b IS IN bList.

Any help would be appreciated.

Upvotes: 0

Views: 3274

Answers (1)

SparkOn
SparkOn

Reputation: 8956

String findQuery = "SELECT T FROM " + MyClass.class.getName() + " T where T.a =:itemA and T.b NOT IN (:bList)";
Query query = factory.getCurrentSession().createQuery(findQuery);
query.setParameter("itemA", a);
query.setParameterList("bList", bList);

Upvotes: 4

Related Questions