memostack
article thumbnail
블로그를 이전하였습니다. 2023년 11월부터 https://bluemiv.tistory.com/에서 블로그를 운영하려고 합니다. 앞으로 해당 블로그의 댓글은 읽지 못할 수 도 있으니 양해바랍니다.
반응형

UserRepository.java

아래 메소드에서 계속 문제가 발생했다.

@Repository
public interface UserRepository extends JpaRepository<User, Long> {

  Optional<User> findFirstByPhoneNumberOrderByIdDesc(String phoneNumber);

}

에러 내용

java.lang.IllegalArgumentException: Failed to create query for method public abstract java.util.Optional com.example.study.repository.UserRepository.findFirstByPhoneNumberOrderByIdDesc(java.lang.String)! Unable to locate Attribute  with the the given name [id] on this ManagedType [com.example.study.model.entity.User]

 

아무리봐도 뭐가 문제인지 못찾았는데,

알고보니 변수명을 id가 아니라 Id로 작성해서 발생한 문제였다.

다시 수정하여 테스트를 돌려본 결과, 성공.

 

결론

JPA를 사용할때는 Java의 변수명을 가지고 매핑하기 때문에 변수명을 오타없이 주의해서 작성해야 함

반응형
블로그를 이전하였습니다. 2023년 11월부터 https://bluemiv.tistory.com/에서 블로그를 운영하려고 합니다. 앞으로 해당 블로그의 댓글은 읽지 못할 수 도 있으니 양해바랍니다.
profile

memostack

@bluemiv_mm

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!