Hibernate HQL NOT IN子句似乎不起作用

时间:2016-04-27 02:16:07

标签: java hibernate hql

// 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);

这是我正在执行的查询。而不是给我a = itemA and b is not in bList的结果,它给我a = itemA and b IS IN bList的结果。

任何帮助都将不胜感激。

1 个答案:

答案 0 :(得分:4)

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);
相关问题