jpa-spring-data-kotlin-mapper

Map Kotlin persistence models and repositories for Spring Data JPA/Hibernate.

14|1|Updated Mar 6, 2026
One-click install
npx skills add https://github.com/Kotlin/kotlin-backend-agent-skills --skill jpa-spring-data-kotlin-mapper
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: jpa-spring-data-kotlin-mapper
Source: https://github.com/Kotlin/kotlin-backend-agent-skills/tree/main/.agents/skills/jpa-spring-data-kotlin-mapper
Command: npx skills add https://github.com/Kotlin/kotlin-backend-agent-skills --skill jpa-spring-data-kotlin-mapper

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Model Kotlin persistence code correctly for Spring Data JPA and Hibernate, including entity design, relationships, fetch plans, repository queries, lazy loading, and common performance traps.

Core Features & Use Cases

  • Do not generate JPA entities as data class; keep transport DTOs separate from persistence entities.
  • Ensure lazy loading safety, proper fetch plans, and correct handling of bidirectional relationships.
  • Address N+1 queries, indexing, and optimization through EntityGraph, JOIN FETCH, and projections.

Quick Start

Apply the mapper to your Kotlin entities and repositories to verify Hibernate compatibility and resolve lazy-loading and N+1 issues.

Frequently Asked Questions about jpa-spring-data-kotlin-mapper

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
Why do my Kotlin JPA entities fail with lazy loading exceptions?

Kotlin JPA entities fail lazy loading when generated as data classes or without explicit nullability, breaking Hibernate proxy initialization. Use non-data class entities with explicit fetch plans to ensure safe lazy loading and avoid runtime exceptions.

How do I map bidirectional relationships in Spring Data JPA without N+1 queries?

Map bidirectional relationships in Spring Data JPA by applying EntityGraph, JOIN FETCH, and projections to optimize fetch plans. This prevents N+1 queries by explicitly fetching required associations during repository queries.

Can I use Kotlin data classes for Hibernate entity mapping?

Kotlin data classes are not suitable for Hibernate entity mapping. You must use non-data class entities to support Hibernate proxy creation, ensure lazy loading safety, and maintain correct identity strategies across persistence contexts.

What's the best way to separate persistence models and DTOs in Kotlin Spring Data repositories?

Separate persistence models and transport DTOs by mapping Kotlin entities as non-data classes and keeping DTOs independent. This ensures explicit nullability for Hibernate compatibility and isolates database concerns from API transport layers.

How do I optimize batch operations and indexing in Spring Data JPA repositories?

Optimize batch operations and indexing in Spring Data JPA by defining explicit fetch strategies, applying EntityGraph, and using JOIN FETCH in repository queries. This resolves N+1 risks and improves performance across typical CRUD operations.

When do I need explicit nullability and identity strategies for Kotlin JPA mappings?

Explicit nullability and identity strategies are required for Kotlin JPA mappings whenever using Hibernate lazy loading or bidirectional relationships. They ensure proxy compatibility, prevent mapping errors, and maintain consistent entity state.