Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/358.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/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 如何在JPA@Query注释中使用IN子句_Java_Hibernate_Jpa_Orm_Entitygraph - Fatal编程技术网

Java 如何在JPA@Query注释中使用IN子句

Java 如何在JPA@Query注释中使用IN子句,java,hibernate,jpa,orm,entitygraph,Java,Hibernate,Jpa,Orm,Entitygraph,我已经定义了这个方法 @Query("select cs from CenterStudy cs where cs.id in (?1)") @EntityGraph(value = "centerStudyAndNotifiedUsers", type = EntityGraph.EntityGraphType.LOAD) List<CenterStudy> findAllByIdsWithCenterAndUsers(List<Long> ids); 我很确定

我已经定义了这个方法

 @Query("select cs from CenterStudy cs where cs.id in (?1)")
 @EntityGraph(value = "centerStudyAndNotifiedUsers", type = EntityGraph.EntityGraphType.LOAD)
 List<CenterStudy> findAllByIdsWithCenterAndUsers(List<Long> ids);
我很确定这与IN子句的定义方式有关

欢迎提出任何建议

public List getDealInfos(List dealid){
public List<DealInfo> getDealInfos(List<String> dealIds) {
        String queryStr = "SELECT NEW com.admin.entity.DealInfo(deal.url, deal.url, deal.url, deal.url, deal.price, deal.value) " + "FROM Deal AS deal where deal.id in :inclList";
        TypedQuery<DealInfo> query = em.createQuery(queryStr, DealInfo.class);
        query.setParameter("inclList", dealIds);
        return query.getResultList();
    }
String queryStr=“选择新的com.admin.entity.DealInfo(deal.url、deal.url、deal.url、deal.url、deal.price、deal.value)”+“来自deal AS deal,其中deal.id位于:inclist中”; TypedQuery query=em.createQuery(queryStr,DealInfo.class); setParameter(“inclist”,dealId); 返回query.getResultList(); }

与JPA 2配合使用这是一个常见问题,
Hibernate
中的一个bug,您可以在以下位置找到:

上面写着:

将JPQL查询与in子句和@NamedEntityGraph组合时 执行查询时,在org.hibernate.param.NamedParameterSpecification.bind(NamedParameterSpecification.java:67)中会出现NullPointerException


因此,您必须删除此处的
@EntityGraph
注释才能解决此问题。

我以前遇到过此问题。我使用命名参数而不是位置参数修复了它。 例如:

替换为:

"Select p from product where p.id in(:idList)" -- OK

因为您使用的是位置参数(?1)而不是命名(:param),并且某些对象需要命名?我也尝试了以下方法,但得到了相同的NullPointerException:
@Query(“从CenterStudy中选择cs,其中cs.id位于(:id)”)@EntityGraph(value=“centerStudyAndNotifiedUsers”,type=EntityGraph.EntityGraphType.LOAD)列表FindAllBydWithCenterAndUsers(@Param(“ids”)列表ID)
"Select p from product where p.id in(?)" -- not working
"Select p from product where p.id in(:idList)" -- OK