1

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);
4
  • ?1 and ?2 are incorrect for native queries. Use ? by itself. Commented Sep 13, 2019 at 8:21
  • same result/error Commented Sep 13, 2019 at 8:26
  • Pardon me but I couldn't see what DBMS you are using, and the keyword LIMIT is not supported by all of them. Commented Sep 13, 2019 at 10:31
  • @Abra PostgreSQL Commented Sep 13, 2019 at 10:43

1 Answer 1

1

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.