下面的這個查詢不起作用,它給我一個例外
@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",
當我使用 MySQL 資料庫時,查詢作業正常。但是現在我用的是H2資料庫,突然就不行了。為什么?我該如何解決?
uj5u.com熱心網友回復:
使用 JPA 會更好。
如果您仍想使用 nativeQuery,請像這樣使用:
@Query(value = "SELECT * FROM account WHERE account_no = :account_no",
nativeQuery = true)
Account findByAccountNo(@Param("account_no") String accountNo);
uj5u.com熱心網友回復:
我在這里猜測,但引數語法“?1”可能對 H2 無效。
這里不需要使用本機查詢,如果您使用 Jpa 語法,它應該可以作業。
此外,您根本不需要在此處指定查詢 - Spring Jpa 應該為您生成查詢。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/431831.html
