java JPQL 查询不使用“NOT IN”命令

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6153077/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 14:34:50  来源:igfitidea点击:

JPQL query not using "NOT IN" command

javajpajpa-2.0jpql

提问by MeanwhileInHell

I'm trying to exclude a bunch of results from a database SELECT using the "NOT IN" keywords, but the exclusion list is still being returned. Using JPQL (JPA2.0) my query looks like:

我正在尝试使用“NOT IN”关键字从数据库 SELECT 中排除一堆结果,但仍在返回排除列表。使用 JPQL (JPA2.0) 我的查询如下所示:

Query query = em.createQuery("SELECT foo.id FROM FooEntity fooEntity WHERE foo.id NOT IN ('" + exclusionList.toString() + "') ORDER BY foo.id").setFirstResult(startPosition).setMaxResults(numberOfAppsToReturn);

exclusionList is a StringBuffer. There is no error reported that I can see, but the id's in the exclusion list are still returned. Is there an alternative JPQL way of doing this?

excludeList 是一个 StringBuffer。没有我可以看到的错误报告,但仍然返回排除列表中的 id。有没有替代的 JPQL 方式来做到这一点?

Thanks in advance.

提前致谢。

回答by Sunil Kumar Sahoo

I think the mistake is in foo. What is foo you have to defined it any where.

我认为错误在foo. 什么是 foo 你必须在任何地方定义它。

Write FooEntity fooinstead of FooEntity fooEntity

FooEntity foo而不是FooEntity fooEntity

Have a look on the following URL.

看看下面的网址。

JPQL, How to NOT select something

JPQL,如何不选择某些东西