Skip to content

chore: add JPA Auditing and BaseEntity configuration#15

Merged
SungbinYang merged 1 commit into
developfrom
chore/14-setup-jpa-auditing
Jan 4, 2026
Merged

chore: add JPA Auditing and BaseEntity configuration#15
SungbinYang merged 1 commit into
developfrom
chore/14-setup-jpa-auditing

Conversation

@SungbinYang

@SungbinYang SungbinYang commented Jan 4, 2026

Copy link
Copy Markdown
Owner

📋 Pull Request

📌 관련 이슈

#14

📝 변경 사항 요약

엔티티 생성/수정 시간 및 사용자 자동 관리를 위한 JPA Auditing 설정

  • @EnableJpaAuditing 활성화
  • AuditorAware 구현 (Spring Security 연동)
  • BaseTimeEntity 생성 (id, createdAt, updatedAt)
  • BaseEntity 생성 (createdBy, updatedBy)

🔄 변경 유형

  • 🐛 버그 수정 (Bug fix)
  • ✨ 새 기능 (New feature)
  • ♻️ 리팩토링 (Refactoring)
  • 🚀 성능 개선 (Performance improvement)
  • 🧪 테스트 (Test)
  • 📚 문서화 (Documentation)
  • 🔧 설정 변경 (Configuration change)
  • 기타 (설명: )

✅ 체크리스트

  • 코드가 정상적으로 동작하는지 확인했습니다

💬 기타

클래스 구조

클래스 필드 용도
BaseTimeEntity id, createdAt, updatedAt User 등
BaseEntity + createdBy, updatedBy Mentoring, Review 등

사용 방법

// 시간만 필요한 경우 (User 등)
@Entity
class User(
    var name: String
) : BaseTimeEntity()

// 시간 + 작성자 필요한 경우 (Mentoring, Review 등)
@Entity
class Mentoring(
    var title: String
) : BaseEntity()

Summary by CodeRabbit

새 기능

  • 모든 데이터의 생성 시간과 최종 수정 시간이 자동으로 기록되어 정확한 변경 이력 추적이 가능합니다
  • 데이터를 생성하고 수정하는 사용자 정보가 자동으로 기록되므로 각 변경에 대한 책임 추적이 가능합니다
  • 완전한 감사 기반 구조를 통해 시스템의 데이터 무결성과 투명성이 강화되었습니다

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai

coderabbitai Bot commented Jan 4, 2026

Copy link
Copy Markdown

Walkthrough

Spring Data JPA 감사 메커니즘을 구현하는 새로운 기본 엔티티 클래스와 설정을 추가합니다. 생성/수정 타임스탬프와 사용자 정보를 자동으로 추적하며, 인증된 사용자를 제공하는 AuditorAware 구현을 포함합니다.

Changes

Cohort / File(s) 변경 사항
JPA 감사 기본 엔티티
src/main/kotlin/im/grit/infrastructure/common/entity/BaseDateTimeEntity.kt
자동 생성 id, createdAt (@CreatedDate), updatedAt (@LastModifiedDate)를 포함하는 추상 MappedSuperclass 추가
기본 엔티티 확장
src/main/kotlin/im/grit/infrastructure/common/entity/BaseEntity.kt
BaseDateTimeEntity를 상속하는 추상 클래스; createdBy (@CreatedBy), updatedBy (@LastModifiedBy) 속성 추가
감사 설정
src/main/kotlin/im/grit/infrastructure/config/audit/AuditConfig.kt
@EnableJpaAuditing 활성화; AuditorAware 빈 제공
감사자 구현
src/main/kotlin/im/grit/infrastructure/config/audit/AuditorAwareImpl.kt
AuditorAware 구현; SecurityContextHolder에서 현재 사용자 추출 및 제공

Sequence Diagram

sequenceDiagram
    participant App as 애플리케이션
    participant JPA as Spring Data JPA
    participant Listener as AuditingEntityListener
    participant Config as AuditConfig
    participant Aware as AuditorAwareImpl
    participant Security as SecurityContextHolder

    App->>Config: 애플리케이션 시작
    Config->>JPA: `@EnableJpaAuditing` 설정
    Config->>Aware: auditorAwareProvider() 빈 등록

    App->>JPA: 엔티티 저장/수정
    JPA->>Listener: 엔티티 변경 감지
    Listener->>Aware: 현재 감사자 조회
    Aware->>Security: 인증된 사용자 조회
    Security-->>Aware: 사용자 정보 또는 "anonymous"
    Aware-->>Listener: Optional<String> 반환
    Listener->>Listener: createdAt/updatedAt 타임스탬프 설정
    Listener->>Listener: createdBy/updatedBy 사용자명 설정
    Listener-->>JPA: 감사 정보 적용
    JPA-->>App: 엔티티 저장 완료
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 새로운 감사 추적의 시작이로다
엔티티마다 생성자와 수정자의 흔적
타임스탐프와 사용자명이 조화롭게
Spring의 마법으로 자동화된 기록
투명한 변화, 완벽한 감시! ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PR 제목이 변경 사항의 주요 내용을 명확하게 요약하고 있습니다. JPA Auditing과 BaseEntity 설정을 추가하는 것이 PR의 핵심이며, 제목이 이를 정확하게 반영하고 있습니다.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chore/14-setup-jpa-auditing

📜 Recent review details

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5110056 and 4125b50.

📒 Files selected for processing (4)
  • src/main/kotlin/im/grit/infrastructure/common/entity/BaseDateTimeEntity.kt
  • src/main/kotlin/im/grit/infrastructure/common/entity/BaseEntity.kt
  • src/main/kotlin/im/grit/infrastructure/config/audit/AuditConfig.kt
  • src/main/kotlin/im/grit/infrastructure/config/audit/AuditorAwareImpl.kt
🧰 Additional context used
📓 Path-based instructions (2)
**/*.kt

⚙️ CodeRabbit configuration file

**/*.kt: - Verify compliance with Kotlin coding conventions

  • Check for safe nullable handling (?.let, ?:, avoid excessive use of !!)
  • Review proper usage of data classes
  • Consider opportunities for extension functions

Files:

  • src/main/kotlin/im/grit/infrastructure/config/audit/AuditorAwareImpl.kt
  • src/main/kotlin/im/grit/infrastructure/config/audit/AuditConfig.kt
  • src/main/kotlin/im/grit/infrastructure/common/entity/BaseEntity.kt
  • src/main/kotlin/im/grit/infrastructure/common/entity/BaseDateTimeEntity.kt
**/entity/**/*.kt

⚙️ CodeRabbit configuration file

**/entity/**/*.kt: - Verify lazy loading (LAZY) is set as default for associations

  • Check for convenience methods in bidirectional relationships

Files:

  • src/main/kotlin/im/grit/infrastructure/common/entity/BaseEntity.kt
  • src/main/kotlin/im/grit/infrastructure/common/entity/BaseDateTimeEntity.kt
🔇 Additional comments (4)
src/main/kotlin/im/grit/infrastructure/config/audit/AuditConfig.kt (1)

8-16: LGTM! JPA Auditing 설정이 올바르게 구성되었습니다.

Spring Data JPA Auditing이 정상적으로 활성화되어 있고, AuditorAware 빈이 적절하게 등록되어 있습니다.

src/main/kotlin/im/grit/infrastructure/config/audit/AuditorAwareImpl.kt (1)

8-22: LGTM! Kotlin 관용구를 잘 활용한 깔끔한 구현입니다.

?.takeIf와 Elvis 연산자(?:)를 활용한 nullable 처리가 적절합니다. AnonymousAuthenticationToken 체크도 올바르게 되어 있습니다.

src/main/kotlin/im/grit/infrastructure/common/entity/BaseEntity.kt (1)

8-20: LGTM! 감사(Auditing) 필드 설계가 적절합니다.

BaseDateTimeEntity를 상속받아 사용자 감사 필드(createdBy, updatedBy)를 추가하는 계층 구조가 깔끔합니다. @EntityListeners는 부모 클래스에서 상속되므로 별도 선언이 필요 없습니다.

src/main/kotlin/im/grit/infrastructure/common/entity/BaseDateTimeEntity.kt (1)

14-31: LGTM! 기본 시간 감사 엔티티가 잘 구성되었습니다.

@EntityListeners(AuditingEntityListener::class)가 부모 클래스에 적절히 배치되어 모든 하위 엔티티가 상속받습니다. id, createdAt, updatedAt 필드 구성이 표준적인 JPA Auditing 패턴을 따릅니다.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@SungbinYang

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jan 4, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@SungbinYang SungbinYang moved this from Backlog to In review in grit-platform-server-project Jan 4, 2026
@SungbinYang SungbinYang merged commit ec9ab4e into develop Jan 4, 2026
2 checks passed
@github-project-automation github-project-automation Bot moved this from In review to Done in grit-platform-server-project Jan 4, 2026
@SungbinYang SungbinYang deleted the chore/14-setup-jpa-auditing branch January 4, 2026 06:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔧 chore 설정/빌드

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant