Light Blue Pointer
본문 바로가기
Developing/개발일지

2024-01-09, Today I Learned @IdClass Composite key in Spring

by Greedy 2024. 1. 9.

📖 How to make Composite Keys in Spring Entity

 

📖Entity에 복합키로 id구성하는 방법 @IdClass, @EmbeddedId

📖 How to make Composite Keys in Spring Entity 1. IdClass로 구현하는 방식 사용 방법은 간단하다! 1) Entity에 id를 설정해준다 @IdClass(UserPostId.class) 클래스에 이 어노테이션을 붙여서 id를 지정해주고 @Id 복합

greedydeveloper.tistory.com

 

🚩Issue : jakarta.validation.UnexpectedTypeException

{"timestamp":"2024-01-09T03:05:08.657+00:00","status":500,"error":"Internal Server Error","path":"/api/v1/posts"}

jakarta.validation.UnexpectedTypeException: HV000030: No validator could be found for constraint 'jakarta.validation.constraints.Size' validating type 'java.lang.Integer'. Check configuration for 'deadlineMins'

Integer validator가 없다고 함

public class SpringValidatorAdapter implements SmartValidator, jakarta.validation.Validator {

이 파일 살펴봄

@Override
	public void validate(Object target, Errors errors) {
		if (this.targetValidator != null) {
			processConstraintViolations(this.targetValidator.validate(target), errors);
		}
	}

Integer가 저기서 취급하는게 아닌가봄

 

⛳Solution : Integer에 @Size 대신 @Min 혹은 @Max 사용

Size로 쓰면 안되고 Min이나 Max annotation을 써야한다고 함

@NotNull
    @Size(max=60)
    Integer deadlineMins,
    @NotNull
    @Size(max=3)
    Integer deadlineHour,

@NotNull
    @Max(59)
    Integer deadlineMins,
    @NotNull
    @Max(3)
    Integer deadlineHour,

 

 

'Developing > 개발일지' 카테고리의 다른 글

2024-01-11, Today I Learned  (1) 2024.01.11
2023-01-10, Today I Learned  (0) 2024.01.10
2024-01-08, Today I Learned  (1) 2024.01.08
2024-01-03, Today I Learned  (0) 2024.01.03
2024-01-02, Today I Learned  (0) 2024.01.02