在我的Spring Boot项目中,我有这个pom:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.1.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
....我想在其中一个存储库中使用自定义原生查询
@Query(nativeQuery=true, "select * from question q where q.id < 5")
public Collection<QuestionEntity> queryAnnotated();但是,当我想给参数nativeQuery = true时,我得到了一个语法错误
Syntax error on token ""select * from question q where q.id < 5"", invalid MemberValuePair发布于 2016-01-13 01:04:16
您应该像这样使用@查询:
@Query(nativeQuery = true, value="select * from question q where q.id < 5")
public Collection<QuestionEntity> queryAnnotated();您的示例中缺少value标记。question表和列q.id应该与数据库的表名和列名完全匹配。
在我的测试应用程序中,它可以工作:
@Repository
public interface QuestionRepository extends JpaRepository<Question, long>{
@Query(nativeQuery=true, value="SELECT * FROM Question q where q.id < 5")
public Collection<Question> findQuestion();
}发布于 2016-01-12 21:14:58
你可以试试这个。根据您的业务需求更改查询和方法。希望它能起作用。
public interface UserRepository extends JpaRepository<User, Long> {
@Query(value = "SELECT * FROM USERS WHERE EMAIL_ADDRESS = ?0", nativeQuery = true)
User findByEmailAddress(String emailAddress);
}https://stackoverflow.com/questions/34744033
复制相似问题