【问题标题】:Hibernate HQL NOT IN clause doesn't seem to workHibernate HQL NOT IN 子句似乎不起作用
【发布时间】:2016-08-21 02:51:39
【问题描述】:
// 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 的结果。

任何帮助将不胜感激。

【问题讨论】:

  • 和 NOT (b IN (:bList)) 怎么样 ?
  • @Hogan 这不是 SQL,而是 HQL。创建查询(不是 NativeQuery)请参阅 stackoverflow.com/questions/6584898/…
  • 请启用 SQL 日志并查看 Hibernate 生成的 SQL 请求。

标签: java hibernate hql


【解决方案1】:
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);

【讨论】:

  • 我确实试过了(在我尝试了我在我的问题中发布的解决方案之前),但它不起作用。长话短说,我有另一个正在运行的进程正在删除我想要提取的记录,这就是我的结果集为空的原因。故事寓意:别傻了
猜你喜欢
  • 2012-03-14
  • 1970-01-01
  • 2014-12-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-06-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多