I’m using JPARepository in SpringBoot and using the @Query
annotation but I get an error
org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet
When using the nativeQuery=true
This is my function:
@Query(value = "select * from table1 where status = ?1 and time <= ?2 LIMIT 2", nativeQuery = true) List<MyModel> findScheduledSmsMessages(Status status, LocalDateTime time);
Advertisement
Answer
I added the following code above my query and
@Modifying
@Transactional
Like this :
@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);