kotlin-backend-jpa-entity-mapping

Model Kotlin JPA entities with identity and equality rules for Spring Data JPA.

302|22|Updated Feb 12, 2026
One-click install
npx skills add https://github.com/JetBrains/skills --skill kotlin-backend-jpa-entity-mapping
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: kotlin-backend-jpa-entity-mapping
Source: https://github.com/JetBrains/skills/tree/main/kotlin-backend-jpa-entity-mapping
Command: npx skills add https://github.com/JetBrains/skills --skill kotlin-backend-jpa-entity-mapping

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Kotlin's data classes and proxying semantics often cause subtle persistence bugs when modeling JPA entities in Spring Data projects. This guide teaches how to design Kotlin persistence layers that work reliably with Hibernate/JPA.

Core Features & Use Cases

  • Entity design rules for Kotlin with JPA: avoid data classes, separate persistence entities from DTOs, and model nullability safely.
  • Identity, equality, and fetch strategy guidance: implement ID-based equality, stable hashCode, and safe toString practices to prevent lazy-loading issues.
  • Uniqueness constraints and common ORM traps: apply database constraints and application logic to prevent duplicates and stale reads.

Quick Start

Apply the Kotlin JPA entity design rules when creating or reviewing persistence models in a Spring Data JPA project.

Frequently Asked Questions about kotlin-backend-jpa-entity-mapping

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

FAQPage Schema
Why does using Kotlin data classes for JPA entities cause persistence bugs?

Kotlin data classes cause persistence bugs because their auto-generated equals and hashCode methods include all properties, triggering unexpected lazy-loading and proxying issues with Hibernate. You should avoid data classes and separate persistence entities from DTOs.

How do I implement equals and hashCode for Kotlin JPA entities to avoid lazy-loading traps?

Implement ID-based equality and stable hashCode for Kotlin JPA entities to avoid lazy-loading traps. Keep toString safe by not triggering uninitialized associations, ensuring reliable proxying and preventing stale reads during Hibernate operations.

Can I use Kotlin data classes with Spring Data JPA and Hibernate without issues?

Kotlin data classes with Spring Data JPA and Hibernate often cause issues due to proxying semantics and auto-generated methods. You should model nullability safely, avoid data classes for persistence entities, and apply database uniqueness constraints.

What is the best way to design identity strategies and uniqueness rules in Kotlin JPA?

The best way to design identity strategies in Kotlin JPA is to apply ID-based identity rules and database uniqueness constraints. Combine these with application logic to prevent duplicates and stale reads, ensuring correct ORM behavior.

How do I handle nullability and uniqueness constraints when designing Kotlin JPA entities?

Handle nullability and uniqueness constraints by modeling entity properties safely and applying database constraints directly. This approach prevents duplicates and stale reads, ensuring reliable persistence layer behavior in Kotlin-based Spring applications.