What problem does it solve?
Kotlin developers often struggle to design JPA entities that work reliably with Hibernate and Spring Data, risking improper equals/hashCode, mutable state pitfalls, and unsafe lazy loading. This skill provides a principled set of rules and patterns to design Kotlin persistence entities that preserve identity, enforce safe fetch plans, and apply correct uniqueness constraints.
Core Features & Use Cases
- Entity design rules: never use data class for JPA entities; use a regular class; keep DTOs separate.
- Identity and equality guidance: implement equals/hashCode based on ID; avoid including mutable fields; ensure safe toString.
- Uniqueness constraints: define database constraints and application guards to prevent duplicates.
- Query and fetch rules: use appropriate fetch plans and caution with lazy loading.
- Common ORM traps: bidirectional associations, proxying, and open-in-view considerations.
- Use case: review and refactor Kotlin JPA entities in a Spring Data project to prevent N+1 and proxies pitfalls.
Quick Start
Review your Kotlin JPA entities in your Spring Data project and apply the rules above to replace data classes with regular entities and implement ID-based identity.