How to search with JpaRepository and nested list of objects?

后端 未结 1 1124
暖寄归人
暖寄归人 2020-12-14 23:35

Description

There is a PersonRepository and Person entity, Person class contains List

相关标签:
1条回答
  • 2020-12-14 23:43

    First, change experienceInMonths from String to int (otherwise you can not compare the string with the number). Then you can try to use this 'sausage':

    List<Person> findByQualifications_experienceInMonthsGreaterThanAndQualifications_experienceInMonthsLessThanAndName(int experienceGreater, int experienceLess, String name);
    

    Or you can try to use this pretty nice method:

    @Query("select p from Person p left join p.qualifications q where q.experienceInMonths > ?1 and q.experienceInMonths < ?2 and q.name = ?3")
    List<Person> findByQualification(int experienceGreater, int experienceLess, String name);
    
    0 讨论(0)
提交回复
热议问题