0

I'm wondering how to convert this query to JPA:

@Query(value = "SELECT u FROM User u " +
        "WHERE u.clList IN (:clList)" +
        "AND ( u.enName like CONCAT('%',:searchBar,'%') OR u.frName like CONCAT('%',:searchBar,'%') ) ")
List<User> getAll(List<Long> clList,String searchBar);

I try this but doesn't work

List<User> findAllByClListInOrEnNameIsLikeIgnoreCaseOrFrNameIsLikeIgnoreCase(Long clList,String enSerach,String frSerch);

My main issue is how to do this

AND ( u.enName like CONCAT('%',:searchBar,'%') OR u.frName like CONCAT('%',:searchBar,'%') )
S3D
  • 109
  • 1
  • 9
  • 1
    Check out answers to this question (https://stackoverflow.com/questions/35788856/spring-data-jpa-how-to-combine-multiple-and-and-or-through-method-name) i personally don't think that it's worth the hassle and having these unreadable method names, but it's always better to know how to do it anyway. – Kamil Bęben Jan 10 '23 at 19:28
  • 1
    I totally agree @Kamil Bęben, thanks for your response – S3D Jan 11 '23 at 20:49

1 Answers1

0

make sure when you are going to the next line you should leave space between like here after "WHERE u.clList IN (:clList)" you didnt leave a space which will return a syntax error. Also practice putting WHERE condition and AND condition inside () like where (condition) and (condition). Also you can directly use LIKE %:var:% without concat though thats just a suggestion not a mistake. Otherwise i cant see any errors. Hope this helps

  • My JPQL , its works and fine , but I want to convert it as a jpa function like this ( findAllByClListInOrEnNameIsLikeIgnoreCaseOrFrNameIsLikeIgnoreCase ) – S3D Jan 11 '23 at 20:51