I tried both, indexed and named parameters, but it doesn't work:
public interface CharacterRepository extends JpaRepository<Character, Long> {
@Query(nativeQuery=true, value="SELECT * FROM Character WHERE pinyin like '%:keyword%'")
List<Character> findByKeyword(@Param("keyword") String keyword);
}
The outcoming sql is:
Hibernate:
SELECT
*
FROM
Character
WHERE
pinyin like '%:keyword%'
Why is the keyword-placeholder not replaced by the parameter I actually pass?
Your query should be like this -
@Query(nativeQuery=true, value="SELECT * FROM Character c WHERE c.pinyin like %:keyword%")
List<Character> findByKeyword(@Param("keyword") String keyword);
Hope it help.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With