麻烦使用@Query与Spring-Boot JPA和Java

use*_*298 2 java spring-data-jpa spring-boot

我刚开始使用spring-boot并且一直在不断地在构建我的项目方面取得进展但是我已经到了需要执行特定查询而不是Spring构建的查询的地步.

这是我的@Query的样子:

@Query("select top 1 * from 'table name' where 'column' like 'value' and    message like 'value' order by 'column' desc")
Run Code Online (Sandbox Code Playgroud)

由于它与工作有关,我不得不更换我们的数据库特定信息,但我认为你们仍然应该能够了解我正在尝试做什么.我的老板想要这个查询,因为如果没有这样的格式,我们会返回很多结果,我们只想要最新的 - 因此是前1和顺序.

我看到的错误是"<operator>或AS预期,得到'1'",到目前为止,我还没有在Google上找到任何内容.

我在这做错了什么?

小智 9

我认为问题是您在@Query中编写了本机查询,但未设置@Query("...", nativeQuery=true),因为此批注在JPQL中默认接受查询.阅读那里的 @Query用法