Spring Data JPA how to pass a variable by using @repository

Viewed 6358

Thank U, guys! I have found the solution:

@Repository
public interface BookRepository extends JpaRepository<Book, Integer>{       
    @Query(value = "select * from Book where find_in_set(:market,market)", nativeQuery = true)
    public List<Book> findBooksByMarcket(@Param("market") String market);
}

Original question

I'm using the @Query annotation to create queries by using the JPA query language and to bind these queries directly to the methods of my repository interface.

My database is created correctly and I'm successful to create some queries except this one:

@Repository
public interface BookRepository extends JpaRepository<Book, Integer>{       
    @Query("select b from Book b where find_in_set(:market,b.market)")
    public List<Book> findBooksByMarcket(@Param("market") String market);
}

I can get the correct result by using the find_in_set function when I check it though MySql. But I cannot reach to pass a variable in java. I have searched though the internet but I cannot find the correct format for it.

please help and thank you guys!

3 Answers
Related