Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java JPQL-插入中的项目列表_Java_Jpa_Jpql - Fatal编程技术网

Java JPQL-插入中的项目列表

Java JPQL-插入中的项目列表,java,jpa,jpql,Java,Jpa,Jpql,在JPA中,在创建查询时,我们可以执行 (" ... where a.name = :name ...") .setParameter("name", user.getName()); 然而,我希望JPQL中是否有我可以做到的方法: (" ... where a.name in (:namelist) ...") .setParameter("namelist", (List<String>)names); 不一定是我上面举例说明的那样。我正在寻找任何方便的方法来将IN(或not

在JPA中,在创建查询时,我们可以执行

(" ... where a.name = :name ...")
.setParameter("name", user.getName());
然而,我希望JPQL中是否有我可以做到的方法:

(" ... where a.name in (:namelist) ...")
.setParameter("namelist", (List<String>)names);
不一定是我上面举例说明的那样。我正在寻找任何方便的方法来将IN(或notin)列表构建到查询中。欢迎提出任何形式的建议。也许有一个apacheutil


否则,我将不得不构造查询并迭代地将项目插入IN列表。

从JPA2开始,它应该可以立即用于:

select a from Something a where a.name in :param
其中:param是正确类型的集合。比如:

List<Product> products =
    em.createQuery("select p from Product p where p.productId in :ids")
    .setParameter("ids", Arrays.asList(980001, 980032, 986712)).getResultList();
列出产品=
em.createQuery(“从产品p中选择p,其中p.productId位于:id中”)
.setParameter(“ids”,Arrays.asList(98000120032,986712)).getResultList();

从JPA2开始,它应该是开箱即用的:

select a from Something a where a.name in :param
其中:param是正确类型的集合。比如:

List<Product> products =
    em.createQuery("select p from Product p where p.productId in :ids")
    .setParameter("ids", Arrays.asList(980001, 980032, 986712)).getResultList();
列出产品=
em.createQuery(“从产品p中选择p,其中p.productId位于:id中”)
.setParameter(“ids”,Arrays.asList(98000120032,986712)).getResultList();