2017-12-14 1 views
1
私は次のようである私の@query、からエラーを取得しています

HQLクエリ:Hibernateは例外

List<User> result = userRepository.findByCityTypeAndName(city, DentistType.valueOf(type), name); 
:私はメソッドを呼び出す私のコントローラから

UserRepository.java

@Query(value = "select u from User u\n" + 
      " where u.city = :city and u.dentistType = :type\n" + 
      " and (u.firstName like ':name%' or u.lastName like ':name%')") 
    List<User> findByCityTypeAndName(@Param("city") String city, @Param("type") DentistType type, @Param("name") String name); 

しかし、get要求を実行すると、findByCityTypeAndNameメソッドが起動され、次のエラーが発生します。

Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessApiUsageException: Parameter with that name [name] did not exist; nested exception is java.lang.IllegalArgumentException: Parameter with that name [name] did not exist] with root cause 

java.lang.IllegalArgumentException: Parameter with that name [name] did not exist 

これを修正する方法はありますか?クエリ

@Query(value = "select u from User u " + 
      " where u.city = :city and u.dentistType = :type " + 
      " and (u.firstName like CONCAT(:name,'%') or u.lastName like CONCAT(:name,'%')") 
    List<User> findByCityTypeAndName(@Param("city") String city, @Param("type") DentistType type, @Param("name") String name); 

で連結を使用して

+3

'のようなクエリ何かせずにメソッドを作成することができます「:名%」は'ことはできません。 'findByCityTypeAndName'メソッドを呼び出す前に、引用符を削除して'% 'を追加する必要があります。 –

+0

ありがとうございました、それは私の問題を修正しました。 – JJey

答えて

0

てみます。また、この

List<User> findByCityAndDentistTypeAndFirstNameStartingWithOrLastNameStartingWith(String city, DentistType type, String firstName, String lastName); 
関連する問題