Parameter does not have a name 예외가 발생하는 경우

eora21·2024년 5월 3일
1
post-thumbnail

예외 발생 상황

Redis 관련 간단한 코드를 작성하던 도중 org.springframework.data.mapping.MappingException: Parameter org.springframework.data.mapping.Parameter@11f45c5 does not have a name 예외를 마주했습니다.

작성한 코드는 아래와 같았습니다.

@Getter
@RedisHash(value = "h3-index")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Paint {

    @Id
    private Long h3Index;

    private Red red;

    private Green green;

    private Blue blue;

    public Paint(long h3Index, int redValue, int greenValue, int blueValue) {
        this.h3Index = h3Index;
        this.red = new Red(redValue);
        this.green = new Green(greenValue);
        this.blue = new Blue(blueValue);
    }
}
public interface PaintRepository extends CrudRepository<Paint, Long> {
    
}
@Test
@DisplayName("Paint 해시 조회")
void findPaint() throws Exception {
    
    // given
    Paint paint = new Paint(3245L, 30, 224, 118);
    paintRepository.save(paint);
    
    // when
    Paint foundPaint = paintRepository.findById(3245L)
            .orElseThrow();
    
    // then
    Assertions.assertThat(findPaint).extracting(Paint::getRed, Paint::getGreen, Paint::getBlue)
            .containsExactly(new Red(30), new Green(224), new Blue(118));
}

해당 코드의 findById 부분에서 예외가 발생하는 것을 확인할 수 있었습니다.

데이터는 잘 저장되어 있는 것을 확인할 수 있었습니다.

내부 클래스들의 필드 name을 불러오지 못 하는 문제

문제는 Red, Green, Blue 내부에 있는 필드의 name을 가져올 때 null이 입력된다는 점이었습니다.

해당 예외가 발생한 근본적인 이유에 대해 잘 작성된 블로그를 참조하여 해결할 수 있습니다.

해결법을 요약하자면 다음과 같습니다.

-parameters 기입

Java Compiler 항목에서 -paramters를 추가합니다.

out 폴더 삭제 후 재실행

컴파일할 때 생성되는 out 폴더를 삭제하고 다시 실행하면 됩니다.

out 폴더가 보이지 않는 경우

해당 설정을 찾아 켜주시면 확인할 수 있습니다.

profile
나누며 타오르는 프로그래머, 타프입니다.

0개의 댓글

관련 채용 정보