에러
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'adminRepository' defined in com.govwebportal.adminservice.domain.data.repository.AdminRepository defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Could not create query for public abstract org.springframework.data.domain.Page com.govwebportal.adminservice.domain.data.repository.custom.CustomAdminRepository.searchAdminByAdminListResDtos(com.govwebportal.adminservice.presentation.admin.AdminListReqDto,org.springframework.data.domain.Pageable); Reason: Failed to create query for method public abstract org.springframework.data.domain.Page com.govwebportal.adminservice.domain.data.repository.custom.CustomAdminRepository.searchAdminByAdminListResDtos(com.govwebportal.adminservice.presentation.admin.AdminListReqDto,org.springframework.data.domain.Pageable); No property 'adminListResDtos' found for type 'Admin'
Caused by: org.springframework.data.repository.query.QueryCreationException: Could not create query for public abstract org.springframework.data.domain.Page com.govwebportal.adminservice.domain.data.repository.custom.CustomAdminRepository.searchAdminByAdminListResDtos(com.govwebportal.adminservice.presentation.admin.AdminListReqDto,org.springframework.data.domain.Pageable); Reason: Failed to create query for method public abstract org.springframework.data.domain.Page com.govwebportal.adminservice.domain.data.repository.custom.CustomAdminRepository.searchAdminByAdminListResDtos(com.govwebportal.adminservice.presentation.admin.AdminListReqDto,org.springframework.data.domain.Pageable); No property 'adminListResDtos' found for type 'Admin'
Caused by: java.lang.IllegalArgumentException: Failed to create query for method public abstract org.springframework.data.domain.Page com.govwebportal.adminservice.domain.data.repository.custom.CustomAdminRepository.searchAdminByAdminListResDtos(com.govwebportal.adminservice.presentation.admin.AdminListReqDto,org.springframework.data.domain.Pageable); No property 'adminListResDtos' found for type 'Admin'
Caused by: org.springframework.data.mapping.PropertyReferenceException: No property 'adminListResDtos' found for type 'Admin'
Spring Data JPA는 메소드 이름을 분석하여 해당 메소드에 대한 쿼리를 자동으로 생성합니다. 이 때, 메소드 이름은 특정 규칙을 따라야 합니다. 예를 들어, findByLastName이라는 메소드는 lastName이라는 속성에 대한 쿼리를 생성합니다. 여기서 By는 쿼리를 생성하는 데 필요한 키워드입니다.
By가 없는 메소드에서 에러가 발생하는 이유는 Spring Data JPA가 해당 메소드의 이름을 분석할 수 없기 때문입니다. By가 없으면 Spring Data JPA는 어떤 속성에 대한 쿼리를 생성해야 하는지 알 수 없습니다.
또한, By 뒤에 DTO의 이름을 넣어도 에러가 발생하는 이유는 Spring Data JPA가 DTO에 대한 쿼리를 생성할 수 없기 때문입니다. Spring Data JPA는 엔티티에 대한 쿼리만 생성할 수 있습니다. 따라서 By 뒤에는 엔티티의 속성 이름이 와야 합니다.
Querydsl을 사용하는 경우에도 메소드 이름에 대한 규칙은 동일합니다. Querydsl은 쿼리를 생성하는 데 사용되는 라이브러리이지만, Spring Data JPA는 여전히 메소드 이름을 분석하여 쿼리를 생성합니다. 따라서 메소드 이름이 규칙을 따르지 않으면 에러가 발생합니다.
이 문제를 해결하려면 메소드 이름을 Spring Data JPA의 규칙에 맞게 변경해야 합니다. 예를 들어, findAdminByEmail이라는 메소드는 Admin 엔티티의 email 속성에 대한 쿼리를 생성합니다. 이와 같이 By 뒤에는 엔티티의 속성 이름이 와야 합니다.
By 키워드의 누락이나 잘못된 사용으로 인해 발생하는 문제는 스프링 데이터 JPA 또는 Querydsl에서 메서드 기반 쿼리 생성 시 일반적으로 발생합니다. 스프링 데이터 리포지토리에서 메서드 이름을 통해 쿼리를 자동으로 생성할 때, 메서드 이름은 매우 엄격한 규칙을 따라야 합니다. 이 규칙은 findBy, existsBy, countBy와 같은 접두사를 포함하며, 이후에는 엔티티의 속성 이름이 대문자로 시작하는 형태로 연결되어야 합니다. By 뒤에는 검색 조건을 나타내는 엔티티의 필드 이름이 와야 하며, 이 필드 이름은 엔티티 클래스 내에 존재해야 합니다.
By가 없거나 잘못된 사용으로 인한 문제By가 누락된 경우: 스프링 데이터는 메서드 이름을 해석할 때 By를 경계로 사용하여 이전 부분은 액션(예: find, count, exists)을, By 이후 부분은 조건을 해석합니다. By가 없으면 메서드 이름을 올바르게 해석할 수 없어 오류가 발생합니다.By 뒤에 오는 필드 이름 문제: By 다음에 오는 필드 이름이 엔티티에 존재하지 않거나 오타가 있는 경우, 스프링 데이터는 해당 필드를 찾을 수 없어 오류를 발생시킵니다. 예를 들어, findByUsername 메서드에서 username 필드가 엔티티에 정의되어 있지 않으면 오류가 발생합니다.Querydsl을 사용하는 경우에도 비슷한 네이밍 문제가 발생할 수 있습니다. Querydsl은 타입-세이프 쿼리를 생성하기 위해 엔티티 클래스를 기반으로 Q클래스를 생성합니다. 이 때, 메서드 이름 또는 쿼리 생성 시 사용하는 필드 이름이 엔티티의 실제 필드 이름과 일치하지 않으면 오류가 발생할 수 있습니다.
By 다음에 올바른 필드 이름이 대문자로 시작하도록 메서드 이름을 수정해야 할 수 있습니다.By 뒤에 사용된 필드 이름이 엔티티 클래스 내에 실제로 존재하는지 확인하세요. 필드 이름이 오타가 나지 않았는지, 정확히 일치하는지 검사합니다.위 문제들은 주로 네이밍 규칙을 엄격히 준수하지 않거나, 엔티티와 리포지토리 메서드 간의 불일치로 인해 발생합니다. 따라서, 스프링 데이터 JPA
의 문서화된 규칙을 따르는 것이 중요합니다. 추가적으로, Querydsl 설정과 사용법을 잘 이해하고 적용하는 것이 필요합니다.
Querydsl Q클래스 생성: Q클래스는 빌드 과정에서 자동으로 생성됩니다. Maven이나 Gradle 설정을 통해 Querydsl 플러그인이 올바르게 설정되어 있는지 확인하세요. Q클래스가 최신 상태인지 확인하기 위해 프로젝트를 클린 빌드하는 것이 좋습니다.
쿼리 메서드 사용: Querydsl을 사용할 때는 JPAQueryFactory를 사용하여 쿼리를 구성하게 됩니다. 이 과정에서 엔티티의 필드 이름을 정확히 사용해야 합니다. 예를 들어, QUser.user.username.eq("someUsername")과 같이 사용할 때, username 필드가 User 엔티티에 존재해야 합니다.
정리하자면, By 키워드의 누락 또는 잘못된 필드 이름 사용은 스프링 데이터 JPA 리포지토리의 메서드 네이밍 규칙을 따르지 않았기 때문에 발생합니다. Querydsl 사용 시에는 Q클래스의 필드 이름을 정확히 맞추어 사용해야 하며, 이 필드 이름들은 엔티티 클래스의 필드 이름과 일치해야 합니다. 문제의 근본 원인을 해결하기 위해서는 메서드 이름과 Q클래스의 사용법을 다시 검토하고, 필요한 경우 스프링 데이터 JPA와 Querydsl의 공식 문서를 참고하여 규칙을 정확히 이해하고 적용해야 합니다.