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/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
意外标记:在hibernate中使用spring数据jpa时的位置_Hibernate_Jpa_Spring Data Jpa - Fatal编程技术网

意外标记:在hibernate中使用spring数据jpa时的位置

意外标记:在hibernate中使用spring数据jpa时的位置,hibernate,jpa,spring-data-jpa,Hibernate,Jpa,Spring Data Jpa,我试图在我的项目中使用spring数据jpa和hibernate。我在repository中添加了注释@Query,试图编写一个hql,其中传入了一个可分页的参数,如下所示: @Query(“从父id为NULL或父id=''的区域中选择名称、代码、id”) 页面findAllRoots(可分页可分页) 但当我试图编译并运行它时,我得到了意想不到的标记:where打印在控制台上。完整信息如下: 原因:java.lang.IllegalArgumentException:org.hibernate.

我试图在我的项目中使用spring数据jpa和hibernate。我在repository中添加了注释@Query,试图编写一个hql,其中传入了一个可分页的参数,如下所示:

@Query(“从父id为NULL或父id=''的区域中选择名称、代码、id”)
页面findAllRoots(可分页可分页)

但当我试图编译并运行它时,我得到了意想不到的标记:where打印在控制台上。完整信息如下:

原因:java.lang.IllegalArgumentException:org.hibernate.hql.internal.ast.QuerySyntaxException:unexpected token:where靠近第1行第14列[从com.nitccs.demo.entity.Region中选择count(where),其中fatherId为NULL或fatherId='']


怎么会这样?我完全糊涂了。为什么不是选择计数(id)之类的?我确信在我的pojo中没有名为where的变量。

在您上面的查询中,您做错了,您期望的是
name,code,I
d以及如何将其转换为
Region
对象

如果需要分页数据,请尝试使用
SpringData规范

来看看这个。所以这应该行得通

select r from Region r where r.fatherId is NULL or r.fatherId=''

谢谢!我在你的指导下把它修好了。似乎我既没有写hql也没有写sql。所以说谢谢的方式就是投票并接受正确的答案。thx,没有你的帮助,我需要更长的时间才能实现它。谢谢你,真的。