상속받은 클래스의 attribute가 저장되지 않을 때 - APPS-sookmyung/2023-POCHAK-server GitHub Wiki
When Inherited Class Attributes not saved to DynamoDB
Jisoo Oh
Written By문제 상황
BaseEntity의 attribute들이 BaseEntity를 상속받은 엔티티들을 저장할 때, 반영되지 않음.
BaseEntity 코드
@Getter
@Setter //Setters are used in aws-dynamodb-sdk
@NoArgsConstructor
public class BaseEntity {
@CreatedDate
@DynamoDBAttribute
@DynamoDBTypeConverted(converter = LocalDateTimeConverter.class)
private LocalDateTime createdDate;
@LastModifiedDate
@DynamoDBAttribute
@DynamoDBTypeConverted(converter = LocalDateTimeConverter.class)
private LocalDateTime lastModifiedDate;
@DynamoDBTypeConvertedEnum
@DynamoDBAttribute
private Status status = Status.PRIVATE; // default
}
해결 과정
방법 찾기
DynamoDBMapper에 해당 속성 역시도 직렬화serialize
해야 함을 알려야 함.
- BaseEntity위에
@DynamoDBDocument
를 사용하여 알려줌!
고친 BaseEntity 클래스 코드
@Getter
@Setter
@NoArgsConstructor
@DynamoDBDocument // add this
public class BaseEntity {
@CreatedDate
@DynamoDBAttribute
@DynamoDBTypeConverted(converter = LocalDateTimeConverter.class)
private LocalDateTime createdDate;
@LastModifiedDate
@DynamoDBAttribute
@DynamoDBTypeConverted(converter = LocalDateTimeConverter.class)
private LocalDateTime lastModifiedDate;
@DynamoDBTypeConvertedEnum
@DynamoDBAttribute
private Status status = Status.PRIVATE; // default
}