인프런 커뮤니티 질문&답변

leemsdong2님의 프로필 이미지
leemsdong2

작성한 질문수

실전! 스프링 데이터 JPA

Projections

findProjectionsByUsername 생성오류

작성

·

345

0

 Error creating bean with name 'memberRepository' defined in study.datajpa.repository.MemberRepository defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Invocation of init method failed; nested exception is org.springframework.data.repository.query.QueryCreationException: Could not create query for public abstract java.util.List study.datajpa.repository.MemberRepository.findProjectionsByUsername(java.lang.String)! Reason: Failed to create query for method public abstract java.util.List study.datajpa.repository.MemberRepository.findProjectionsByUsername(java.lang.String)! null; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract java.util.List study.datajpa.repository.MemberRepository.findProjectionsByUsername(java.lang.String)! null

 

이렇게 repository에서 저 네임메서드가 생성이 안되어서 오류가 뜨는데 해결이 안됩니다..

답변 2

1

저도 부트 2.6.3에서는 안되는거같습니다.

2.6.2로 낮추니까 돌아가네요

0

안녕하세요. leemsdong2님, 공식 서포터즈 David입니다.

해당 리포지토리 코드도 함께 올려주세요.

감사합니다.

leemsdong2님의 프로필 이미지
leemsdong2
질문자

public interface MemberRepository extends JpaRepository<Member,Long>, MemberRepositoryCustom{


@Query("select m from Member m where m.username=:name and m.age =:age")
List<Member> findUser(@Param("name") String username, @Param("age") int age);

@Query("select m.username from Member m")
List<String> findUsernameList();

@Query("select new study.datajpa.dto.MemberDto(m.id, m.username, t.name) from Member m join m.team t")
List<MemberDto> findMemberDto();

@Query("select m from Member m where m.username in :names")
List<Member> findByNames(@Param("names") List<String> names);

// @Query("select m from Member m",
// countQuery = "select count(m.username) from Member m")
Page<Member> findByAge(int age, Pageable pageable);

@Modifying(clearAutomatically = true)
@Query("update Member m set m.age=m.age+1 where m.age>=:age")
int bulkAgePlus(@Param("age") int age);

@Query("select m from Member m join fetch m.team")
List<Member> findMemberFetchJoin();

@EntityGraph(attributePaths = {"team"})
List<Member> findByAge(@Param("age") int age);

List<UsernameOnly> findProjectionsByUsername(String username);

}
leemsdong2님의 프로필 이미지
leemsdong2
질문자

public interface UsernameOnly {

String getUsername();
}

혹시해서 이것도 올립니다

Member 클래스도 올려주실 수 있으세요?

leemsdong2님의 프로필 이미지
leemsdong2
질문자

@Entity
@Getter
@Setter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@ToString(of = {"id","username","team"})
public class Member extends BaseEntity{

@Id @GeneratedValue
@Column(name = "member_id")
private Long id;

private String username;

private int age;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "team_id")
private Team team;

public Member(String username) {
this.username = username;
}

public Member(String username, int i, Team team) {
this.username = username;
this.age = i;
if(team!=null){
changeTeam(team);
}
}

public Member(String username, int age) {
this(username, age, null);
}


public void changeTeam(Team team){
this.team = team;
team.getMembers().add(this);
}
}

혹시 Spring Data Jpa 버전이 최신버전이실까요?

만약 최신버전이시라면 아래 글 답변을 참고하셔서 Spring Boot 버전 또는 Spring Data Jpa 버전을 낮춰보시고 다시 시도해주시겠어요?

https://www.inflearn.com/questions/444705

leemsdong2님의 프로필 이미지
leemsdong2

작성한 질문수

질문하기