kotlin avatar

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-code

Installs 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 class for JPA entities. Use a regular class. Keep data class for 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 lateinit only 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

More from kotlin/kotlin-agent-skills

All 5
1alirezarezvani avatarsenior-backendalirezarezvani/claude-skillsDesigns and implements backend systems including REST APIs, microservices, database architectures, authentication flows, and security hardening. Use when the us1.7Kskills.sh installs
2alchemyplatform avataralchemy-apialchemyplatform/skillsWire Alchemy into application code (server, backend, dApp, script) using a standard API key. Preferred app-integration path for normal server/backend usage. Cov1.7Kskills.sh installs
3jezweb avatard1-drizzle-schemajezweb/claude-skillsGenerate Drizzle ORM schemas for Cloudflare D1 databases with correct D1-specific patterns. Produces schema files, migration commands, type exports, and DATABAS1.7Kskills.sh installs
4loops-so avatarloops-apiloops-so/skillsUse this skill whenever the user wants to integrate Loops from application code, backend services, webhook handlers, or server-side automation. This includes th1.6Kskills.sh installs
5jezweb avatarhono-api-scaffolderjezweb/claude-skillsScaffold Hono API routes for Cloudflare Workers. Produces route files, middleware, typed bindings, Zod validation, error handling, and API_ENDPOINTS.md document1.6Kskills.sh installs
6ccheney avatarpostgres-drizzleccheney/robust-skillsProactively apply when creating APIs, backends, or data models. Triggers on PostgreSQL, Postgres, Drizzle, drizzle-orm, drizzle-kit, database, schema, pgTable, 1.5Kskills.sh installs