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
부분에서 예외가 발생하는 것을 확인할 수 있었습니다.
데이터는 잘 저장되어 있는 것을 확인할 수 있었습니다.
문제는 Red, Green, Blue 내부에 있는 필드의 name을 가져올 때 null이 입력된다는 점이었습니다.
해당 예외가 발생한 근본적인 이유에 대해 잘 작성된 블로그를 참조하여 해결할 수 있습니다.
해결법을 요약하자면 다음과 같습니다.
Java Compiler 항목에서 -paramters를 추가합니다.
컴파일할 때 생성되는 out 폴더를 삭제하고 다시 실행하면 됩니다.
해당 설정을 찾아 켜주시면 확인할 수 있습니다.