Skip to content
Advertisement

My Spring JPA queries do not work with H2

This query below does not work and it generates me an exception

@Query(value = "SELECT * FROM account WHERE account_no = ?1",
nativeQuery = true)
Account findByAccountNo(String accountNo);
 "message": "could not prepare statement; SQL [SELECT * FROM account WHERE account_no = ?]; nested exception is org.hibernate.exception.SQLGrammarException: could not prepare statement",

When I used the MySQL database, the query worked fine. But now that I am using the H2 database, it suddenly does not work. Why? How do I fix this?

Advertisement

Answer

It would be better to use JPA.

If you still wanna use nativeQuery, use like this:

@Query(value = "SELECT * FROM account WHERE account_no = :account_no",
nativeQuery = true)
Account findByAccountNo(@Param("account_no") String accountNo);
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement