
Kotlin Backend Jpa Entity Mapping
This one walks you through the Kotlin-specific traps in JPA entity mapping, especially why data classes break Hibernate's identity semantics and corrupt Set membership after state changes. It covers ID-based equality patterns, uniqueness constraints at both the database and application layer to avoid race conditions, and the usual ORM hazards like N+1 queries and lazy load triggers. The guardrails are sensible: no data class entities, no blanket FetchType.EAGER fixes, maintain both sides of bidirectional associations. If you're debugging LazyInitializationException or wondering why your entity disappeared from a HashSet after you changed a field, this is the reference you want. JetBrains authored it, so the Kotlin idioms are sound.
- skills.sh installs
- 1.8K
- GitHub stars
- 1.1K
- last updated
- Aug 21, 2026
Install
$ npx -y skills add kotlin/kotlin-agent-skills --skill kotlin-backend-jpa-entity-mapping --agent claude-codeInstalls into .claude/skills of the current project.
Files
JPA Entity Mapping for Kotlin
Kotlin's data class is natural for DTOs but dangerous for JPA entities. Hibernate relies on
identity semantics that data class breaks: equals/hashCode over all fields corrupts
Set/Map membership after state changes, and auto-generated copy() creates detached
duplicates of managed entities.
This skill teaches correct entity design, identity strategies, and uniqueness constraints for Kotlin + Spring Data JPA projects.
Entity Design Rules
- Never use
data classfor JPA entities. Use a regularclass. Keepdata classfor DTOs. - Keep transport DTOs and persistence entities separate unless the project clearly uses a shared model.
- Model required columns as non-null only when object construction and persistence lifecycle make it safe.
- Use
lateinitonly when the project already accepts that tradeoff and the lifecycle is safe. - Verify
kotlin("plugin.jpa")or equivalent no-arg support when JPA entities exist. - Verify classes and members are compatible with proxying where needed.
Identity and Equality
Sponsors
Details
- Repository
- github.com/kotlin/kotlin-agent-skills
- Categories
- Backend & APIs, AI & Agent Building, Mobile Development, Java & JVM, Design & UI/UX, Databases
- First seen
- Jun 3, 2026