@DynamicUpdate

@DynamicUpdate

Update문 수행하는데, JPARepository에 save만 있네?

·

1 min read

@PatchMapping 으로 update 문을 수행하는데, save()만 있다.

put 메서드를 사용해도 되겠지만, 프로퍼티가 많을수록 비효율적이다.

그래서 변경된 값에만 적용할 수 있도록 @DynamicUpdate를 사용할 수 있다

등록된 정보 조회

GET http://localhost:8080/developers/newbie

HTTP/1.1 200 
Content-Type: application/json
Transfer-Encoding: chunked
Date: Sat, 05 Aug 2023 14:38:27 GMT
Keep-Alive: timeout=60
Connection: keep-alive

{
  "developerLevel": "NEW",
  "developerSkillType": "BACK_END",
  "experienceYears": 2,
  "memberId": "newbie",
  "name": "okjaeook",
  "age": 26
}
응답 파일이 저장되었습니다.
> 2023-08-05T233827.200.json

Response code: 200; Time: 13ms (13 ms); Content length: 123 bytes (123 B)

HTTP Patch 요청

PATCH http://localhost:8080/developer/newbie

HTTP/1.1 200 
Content-Type: application/json
Transfer-Encoding: chunked
Date: Sat, 05 Aug 2023 14:28:03 GMT
Keep-Alive: timeout=60
Connection: keep-alive

{
  "developerLevel": "JUNGNIOR",
  "developerSkillType": "FRONT_END",
  "experienceYears": 5,
  "memberId": "newbie",
  "name": "okjaeook",
  "age": 26
}
응답 파일이 저장되었습니다.
> 2023-08-05T232803.200.json

Response code: 200; Time: 36ms (36 ms); Content length: 129 bytes (129 B)

@DynamicUpdate 없이 @PatchMapping

Hibernate: 
    /* update
        for com.developers.dmaker.entity.Developer */update developer 
    set
        age=?,
        created_at=?,
        developer_level=?,
        developer_skill_type=?,
        experience_years=?,
        member_id=?,
        name=?,
        status_code=?,
        updated_at=? 
    where
        id=?

@DynamicUpdate 적용 @PatchMapping

Hibernate: 
    /* update
        for com.developers.dmaker.entity.Developer */update developer 
    set
        developer_level=?,
        developer_skill_type=?,
        experience_years=?,
        updated_at=? 
    where
        id=?