jpa-spring-data-kotlin-mapper

작성자: kotlin

Kotlin 지속성 코드를 Spring Data JPA 및 Hibernate에 맞게 올바르게 모델링하며, 엔티티 설계, 관계, 페치 계획, 리포지토리 쿼리, 지연 로딩 등을 포함합니다.

npx skills add https://github.com/kotlin/kotlin-backend-agent-skills --skill jpa-spring-data-kotlin-mapper

JPA Spring Data Kotlin Mapper

Source mapping: Tier 1 critical skill derived from Kotlin_Spring_Developer_Pipeline.md (SK-10).

Mission

Generate and review persistence mappings that are correct for both Hibernate semantics and Kotlin semantics. Prevent bugs that compile cleanly but fail under lazy loading, dirty checking, identity comparison, or query load.

Read First

  • Entity classes and mapped superclasses.
  • Repository interfaces and custom queries.
  • Relevant service methods and transaction boundaries.
  • SQL logs, execution plans, or symptoms such as N+1, deadlocks, or stale reads.
  • Build files to verify JPA-related Kotlin compiler plugins.

Entity Design Rules

  • Do not generate JPA entities as data class.
  • Keep transport DTOs and persistence entities separate unless the repository clearly uses a shared model on purpose.
  • Model required columns as non-null only when object construction and persistence lifecycle make that safe.
  • Treat lazy associations and optional associations carefully. Nullable is often the honest model.
  • Use lateinit only when the project already accepts that tradeoff and the lifecycle is safe.

Identity And Equality Rules

  • Never accept all-field equals and hashCode generated by a data class entity.
  • Follow project conventions when they already define an entity identity strategy.
  • If no convention exists, choose an identity approach that is stable under persistence and proxying, then explain the tradeoff.
  • Be explicit about mutable fields and lazy associations when discussing equality semantics.

Query And Fetch Rules

  • Diagnose N+1 by looking at actual query count or SQL logs, not by guessing from annotations alone.
  • Prefer targeted fetch solutions:
    • @EntityGraph
    • JOIN FETCH
    • batch fetching
    • DTO projection
  • Be careful with collection fetch joins plus pagination. Call out the tradeoff instead of hiding it.
  • Use indexes and uniqueness constraints to support real query patterns and idempotency guarantees.

Advanced ORM Traps

  • Maintain both sides of bidirectional associations in domain methods or helper functions. Half-updated object graphs are a common source of subtle bugs.
  • orphanRemoval and cascade remove are not interchangeable. Explain the lifecycle semantics before choosing one.
  • toString, debug logging, JSON serialization, and IDE inspection can trigger lazy loads. Treat them as potential side effects, not harmless utilities.
  • Bulk update or delete queries bypass the persistence context and lifecycle callbacks. Call out when subsequent reads may be stale until clear or reload.
  • Multiple bag fetches can explode under Hibernate. If a collection-heavy fetch plan looks "obviously convenient," verify whether the ORM can execute it safely.
  • Set-based collections plus mutable equality are especially dangerous. Collection membership can break after entity state changes.
  • @Version is usually the clearest optimistic concurrency mechanism when concurrent updates matter. Mention it explicitly when the use case can lose updates.
  • If open-in-view is disabled, DTO mapping that touches lazy fields must happen inside a deliberate transaction boundary.

Expert Heuristics

  • Choose entity shape for write correctness first and read shape second. If reads need a different shape, use projections or dedicated queries.
  • If a query is hot and read-only, DTO projection is often a better optimization than tuning entity graphs indefinitely.
  • If a relationship exists only to simplify one query, question whether it belongs in the entity model or in a query model.
  • Treat database indexes as part of the persistence design, not as a late production optimization.

Kotlin-Specific Checks

  • Verify kotlin("plugin.jpa") or equivalent no-arg support when JPA entities exist.
  • Verify classes and members are compatible with proxying where needed.
  • Verify nullability reflects database truth rather than wishful API design.
  • Verify repository return types and service expectations agree on null handling.

Output Contract

Return these sections:

  • Persistence model: the entity and relationship shape that should exist.
  • Correctness risks: identity, lazy loading, transactional access, and nullability traps.
  • Performance risks: N+1, fetch plan, query shape, pagination, and index concerns.
  • Recommended changes: entity, repository, and query updates in minimal-diff form.
  • Verification: tests or SQL-level checks that confirm the mapping works as intended.

Guardrails

  • Do not recommend FetchType.EAGER everywhere to silence lazy loading symptoms.
  • Do not expose entities directly through API responses by default.
  • Do not use data class entities.
  • Do not claim an N+1 fix without explaining how the fetch plan changes query behavior.
  • Do not place all persistence intelligence in repositories if the service layer controls the real access pattern.

Quality Bar

A good run of this skill improves correctness and query behavior together. A bad run proposes mappings that look neat in Kotlin but violate JPA identity, proxy, or loading semantics.

kotlin의 다른 스킬

ci-cd-containerization-advisor
kotlin
재현 가능한 빌드, 이미지 및 배포 파이프라인을 설계합니다. Kotlin 및 Spring 애플리케이션을 대상으로 하며, CI 검증, 계층형 컨테이너, 롤아웃 안전성 등을 포함합니다.
official
configuration-properties-profiles-kotlin-safe
kotlin
Design and diagnose Spring configuration, profiles, and `@ConfigurationProperties` binding for Kotlin applications. Use when property binding fails,…
official
dependency-conflict-resolver
kotlin
Diagnose and resolve Gradle and Spring classpath conflicts, version drift, and binary incompatibilities in Kotlin applications. Use when `NoSuchMethodError`,…
official
domain-decomposition-api-design-advisor
kotlin
구현을 시작하기 전에 비즈니스 범위를 경계 컨텍스트, 모듈 또는 서비스 경계, 워크플로우, API 계약으로 분해합니다. 새로운 것을 설계할 때 사용하세요.
official
error-model-validation-architect
kotlin
Kotlin과 Spring 서비스를 위한 일관된 API 검증 및 오류 처리 동작을 설계하고 구현합니다. 오류 페이로드를 정의하거나 프레임워크를 매핑할 때 사용합니다.
official
gradle-kotlin-dsl-doctor
kotlin
Generate, debug, and repair Kotlin + Spring Gradle builds with minimal, compatible changes. Use when `build.gradle.kts` or `settings.gradle.kts` is failing,…
official
integration-resilience-engineer
kotlin
탄력적인 HTTP, 메시징, 예약 통합을 Kotlin 및 Spring 서비스용으로 설계하며 명시적인 타임아웃 예산, 재시도, 멱등성, 서킷 브레이커를 포함합니다.
official
jackson-kotlin-serialization-specialist
kotlin
Kotlin과 Jackson을 사용하는 Spring 애플리케이션에서 JSON 직렬화 및 역직렬화 동작을 진단하고 설계합니다. DTO 역직렬화 실패 시, 기본값…
official