• 카테고리

    질문 & 답변
  • 세부 분야

    백엔드

  • 해결 여부

    미해결

JpaMetamodelEntityInformation 내부의 isNew 메서드에서 조건 분기 시 다음 조건은 무엇을 의미하나요?

24.03.16 15:34 작성 조회수 76

0

public boolean isNew(T entity) {
  if (!this.versionAttribute.isEmpty() && !(Boolean)this.versionAttribute.map(Attribute::getJavaType).map(Class::isPrimitive).orElse(false)) {
    BeanWrapper wrapper = new DirectFieldAccessFallbackBeanWrapper(entity);
    return (Boolean)this.versionAttribute.map((it) -> {
      return wrapper.getPropertyValue(it.getName()) == null;
    }).orElse(true);
  } else {
    return super.isNew(entity);
  }
}

 

조건문을 타지 않고 else 절로 넘어가면 super.isNew()를 호출하고, 상위 추상 클래스인 AbstractEntityInformation 클래스의 isNew() 메서드에서 Entity id 필드가 Null, 0L인지 판단하는 걸로 이해했습니다.

강의 범위가 아니긴 하지만 JpaMetamodelEntityInformation 클래스의 isNew() 내에서 versionAttribute가 존재하는지 확인하는 부분은 어떤 것을 확인하는 것인지 궁금합니다.

답변 1

답변을 작성해보세요.

0

David님의 프로필

David

2024.03.17

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

아래 글을 참고해 주세요.

https://junhyunny.github.io/spring-boot/jpa/junit/version-annotation-warning/

감사합니다.