【发布时间】:2018-09-16 02:29:57
【问题描述】:
我正在尝试在 Spring Boot 中运行一个简单的插入查询,但我无法这样做。
查询:
@Modifying
@Query(value = "insert into Local(userId,name,address,pin) VALUES (:userId,:name,:address,:pin)", nativeQuery = true)
List < Local > insertattributes(@Param("userId")String userId,@Param("address") String address ,@Param("name")String name,@Param("pin") String pin);
控制器:
@RequestMapping("insertattributes/{userId}/{name}/{address}/{pin}")
@ResponseBody
public List < Local > insertAttributes(@PathVariable String userId, @PathVariable String name, @PathVariable String address, @PathVariable String pin) {
return localService.insertattributes(userId,name,address,pin);
}
错误:
o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 0, SQLState: S1009
o.h.engine.jdbc.spi.SqlExceptionHelper : Can not issue data manipulation statements with executeQuery().
[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.orm.jpa.JpaSystemException: could not extract ResultSet; nested exception is org.hibernate.exception.GenericJDBCException: could not extract ResultSet] with root cause
java.sql.SQLException: Can not issue data manipulation statements with executeQuery().
【问题讨论】:
-
您在存储库中的
insertattributes方法应该是void。在插入期间期望List<Local>是不合适的 -
我想缓存响应。这就是我试图返回列表的原因。
标签: spring-boot spring-data-jpa hibernate-native-query