🙈 1. 문제 파악
현재 Account
도메인에선, soft delete
방식으로 계정 삭제를 구현하고 있다.
하지만, JpaRepository를 사용하고 있는 만큼 delete
메소드의 오용으로 잘못된 동작을 유발할 수 있음을 알게됐다.
이점을 해결하고자 한다.
또한, 간단한테스트를 위해
- Spring Data JPA를 사용하는 상황에선, 기존
delete
메소드를 오버라이드 하고자 할때, 처리하는데 어려움을 겪게 된다.
💡 2. 해결 방안
공식문서를 통해, JPA의 시그니처 기반 쿼리 생성 로직이 Repository
마커 인터페이스를 상속했는지 여부를 기준으로 판단되는 점을 발견했다.
Central repository marker interface. Captures the domain type to manage as well as the domain type's id type. General purpose is to hold type information as well as being able to discover interfaces that extend this one during classpath scanning for easy Spring bean creation.
Domain repositories extending this interface can selectively expose CRUD methods by simply declaring methods of the same signature as those declared in CrudRepository.
요악하자면, Repository
인터페이스를 상속하는 인터페이스를 구현하면, 해당 인터페이스가 정의하는 메소드 시그니처를 바탕으로 쿼리가 만들어진단 것입니다.
기존에 JpaRepository
를 굳이 상속받을 필요없이, Repository
를 상속받고, 필요한 메소드만 노출시킬 수 있습니다.
이를 바탕으로 리팩토링을 시작해보겠습니다.
✍️ 3. 해결 과정
⭐️ 4. 깨달은 점
'Spring > SpringBoot' 카테고리의 다른 글
Spring boot - @Transactional 전파 주의 사항 (0) | 2025.01.13 |
---|---|
Spring boot - Cache (2) 페이지 조회 캐싱 (0) | 2025.01.08 |
Spring boot - Cache (0) | 2025.01.07 |
[SpringBoot] 스프링의 에러처리 탐구 (0) | 2024.01.17 |
[Spring] Spring Security 인증 구성 (0) | 2024.01.02 |