0

here's my query

    SELECT 
  tb.id AS id,
  tb.title AS title 
FROM
  tbl_batter tb 
WHERE tb.`title` LIKE '%waugh%' ;

here's the code at repository

@Repository
public interface BatterRepository extends JpaRepository<Batter, Long> {
    @Query(value = "SELECT \n" +
            "  tb.id AS id,\n" +
            "  tb.title AS title \n" +
            "FROM\n" +
            "  tbl_batter tb \n" +
            "WHERE tb.`title` LIKE %:searchKey%", nativeQuery = true)
    List<Object[]> getData(@Param("searchKey") String searchKey);
}

Would be a huge favor if anyone could tell what I'm doing wrong while using version 2.3.3 I'm getting list empty while using 2.3.3 and getting list of 2 objects while using 1.5.7

I'm suppose to get 2 objects in the list and that's not happening in case of using 2.3.3

  • Pls refer this - https://stackoverflow.com/questions/25362540/like-query-in-spring-jparepository similar issue with resolution, – Tejaskumar Dec 02 '20 at 08:58
  • thank you for the suggestion, hopefully they would reply bout why it's not working on spring boot 2.3.3 –  Dec 02 '20 at 10:03

1 Answers1

0

Try this:

@Repository
public interface BatterRepository extends JpaRepository<Batter, Long> {
    @Query(value = "SELECT " +
            "  tb.id AS id," +
            "  tb.title AS title " +
            "FROM" +
            "  tbl_batter tb " +
            "WHERE tb.title LIKE '?1' ", nativeQuery = true)
    List<Object[]> getData(String searchKey);
}
Renis1235
  • 4,116
  • 3
  • 15
  • 27