我希望在我的Spring桌面应用程序中运行此查询
SET SQL_SAFE_UPDATES = 0;
应该是GET请求还是PUT请求?我都尝试过但没有成功。
目前我正在尝试
@GetMapping("/orderbook/safeMode")
private void setSafeMode() {
orderBookRepository.setSafeMode();
}
@Query(value = "SET SQL_SAFE_UPDATES = 0;", nativeQuery = true)
void setSafeMode();
但是它给出了一个错误
2019-10-18 11:38:37.844 ERROR 12112 --- [nio-8080-exec-2] o.h.engine.jdbc.spi.SqlExceptionHelper : ResultSet is from UPDATE. No Data.
2019-10-18 11:38:37.851 ERROR 12112 --- [nio-8080-exec-2] o.a.c.c.C.[.[.[/].[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 execute query; nested exception is org.hibernate.exception.GenericJDBCException: could not execute query] with root cause
java.sql.SQLException: ResultSet is from UPDATE. No Data.
任何建议请
最佳答案
它通过向存储库方法添加@Modifying和@Transactional批注来工作
@Modifying
@Transactional
@Query(value = "SET SQL_SAFE_UPDATES = 0;", nativeQuery = true)
void setSafeMode();
感谢
Nikolay Shevchenko
建议@Modifying注释重要链接以了解更多
Do we need both @Transaction and @Modifying annotation in Spring?
why do we have to use @Modifying annotation for queries in Data Jpa