Soft Delete를 선택적으로 적용하는 방법 (cc. @FilterDef, @Filter) #160
songsunkook
started this conversation in
문서화
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
기존
@Where(clause = "is_deleted=0")
를 엔티티 클래스에 적용하여 Soft Delete되지 않은 정보만 접근할 수 있도록 제한할 수 있다.문제점
@Where
은 조건에 성립하는 정보만 접근할 수 있도록 도와주지만 그 조건을 임의로 풀 수 없다. 결국 Soft Delete된 정보까지 조회가 필요한 경우가 생기면(ex. admin) 원활한 기능 수행이 어려워진다.해결방안
@Where
대신@FilterDef
와@Filter
를 사용한다.@FilterDef
는@Where
와 달리 조건을 선택적으로 적용할 수 있다.사용 방법
Entity Class
엔티티 클래스에
@FilterDef
와@Filter
를 작성한다.Service Class
엔티티 클래스에 접근할 클래스에서는 EntityManager가 필요하기 때문에 이를 의존성 주입으로 불러와야 한다.
사용 절차는 다음과 같다.
주의사항
Filter와 Session을 import할 때 여러 라이브러리가 나올텐데, 해당 기능은 hibernate에서 제공하는 것이기 때문에 hibernate의 라이브러리를 import해야 한다.
참고
Beta Was this translation helpful? Give feedback.
All reactions