我在 SpringBoot 中使用 JPARepository 并使用 @Query
注释,但收到错误
org.springframework.dao.InvalidDataAccessResourceUsageException:无法提取结果集; SQL [不适用];嵌套异常是org.hibernate.exception.SQLGrammarException:无法提取ResultSet
使用nativeQuery=true
时
这是我的功能:
@Query(value = "select * from table1 where status = ?1 and time <= ?2 LIMIT 2", nativeQuery = true)
List<MyModel> findScheduledSmsMessages(Status status, LocalDateTime time);
最佳答案
我在查询上方添加了以下代码,并且
@修改
@事务性
像这样:
@Modifying
@Transactional
@Query(value = "DELETE FROM played_sheet WHERE user_id = ?1 AND sheet_music_id = ?2", nativeQuery = true)
void deleteByUserIdAndSheetMusicId(Integer userId,Integer sheetMusicId);
关于java - 在 JPA 中使用 nativeQuery 时出现“无法提取 ResultSet”错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57919634/