File tree Expand file tree Collapse file tree 4 files changed +84
-0
lines changed
src/main/java/com/back/matchduo/global Expand file tree Collapse file tree 4 files changed +84
-0
lines changed Original file line number Diff line number Diff line change 1+ package com .back .matchduo .global .config ;
2+
3+ import org .springframework .context .annotation .Configuration ;
4+ import org .springframework .data .jpa .repository .config .EnableJpaAuditing ;
5+
6+ @ Configuration
7+ @ EnableJpaAuditing
8+ public class JpaConfig {
9+ }
Original file line number Diff line number Diff line change 1+ package com .back .matchduo .global .config ;
2+
3+ import jakarta .annotation .PostConstruct ;
4+ import jakarta .persistence .EntityManager ;
5+ import lombok .RequiredArgsConstructor ;
6+ import org .hibernate .Session ;
7+ import org .springframework .stereotype .Component ;
8+
9+ /**
10+ * Soft Delete된 데이터(is_active = false)가
11+ * 기본 조회(JPQL, Repository)에서 자동으로 제외되도록 Hibernate Filter를 활성화하는 설정
12+ */
13+ @ Component
14+ @ RequiredArgsConstructor
15+ public class SoftDeleteFilterConfig {
16+
17+ private final EntityManager entityManager ;
18+
19+ @ PostConstruct
20+ public void enableFilter () {
21+ // Hibernate Session 얻기
22+ Session session = entityManager .unwrap (Session .class );
23+
24+ // softDeleteFilter 활성화 (is_active = true 조건을 전역적으로 적용)
25+ session .enableFilter ("softDeleteFilter" );
26+ }
27+ }
Original file line number Diff line number Diff line change 1+ package com .back .matchduo .global .entity ;
2+
3+ import jakarta .persistence .Column ;
4+ import jakarta .persistence .EntityListeners ;
5+ import jakarta .persistence .MappedSuperclass ;
6+ import lombok .Getter ;
7+ import org .springframework .data .annotation .CreatedDate ;
8+ import org .springframework .data .annotation .LastModifiedDate ;
9+ import org .springframework .data .jpa .domain .support .AuditingEntityListener ;
10+
11+ import java .time .LocalDateTime ;
12+
13+ @ MappedSuperclass
14+ @ EntityListeners (AuditingEntityListener .class )
15+ @ Getter
16+ public abstract class BaseEntity {
17+
18+ @ CreatedDate
19+ @ Column (nullable = false , updatable = false )
20+ private LocalDateTime createdAt ;
21+
22+ @ LastModifiedDate
23+ @ Column (nullable = false )
24+ private LocalDateTime updatedAt ;
25+
26+ // soft delete를 쓴다면 추가
27+ @ Column
28+ private LocalDateTime deletedAt ;
29+
30+ @ Column (nullable = false )
31+ private Boolean isActive = true ;
32+
33+ public void deactivate () {
34+ this .isActive = false ;
35+ this .deletedAt = LocalDateTime .now ();
36+ }
37+ }
Original file line number Diff line number Diff line change 1+ package com .back .matchduo .global .entity ;
2+
3+ import jakarta .persistence .MappedSuperclass ;
4+ import org .hibernate .annotations .Filter ;
5+ import org .hibernate .annotations .FilterDef ;
6+
7+ @ MappedSuperclass
8+ @ FilterDef (name = "softDeleteFilter" )
9+ @ Filter (name = "softDeleteFilter" , condition = "is_active = true" )
10+ public abstract class SoftDeletableEntity extends BaseEntity {
11+ }
You can’t perform that action at this time.
0 commit comments