Jakarta Persistence (JPA) was designed for Java, creating friction with Kotlin's defaults like final classes, immutable properties, and null safety. To build reliable persistence layers, avoid data classes for entities, use regular open classes with mutable properties, configure the no-arg and all-open compiler plugins, stick to field-based access, and make all entity fields nullable (including primary keys with generated values). Default values in constructors won't apply when loading from the database. Kotlin 2.2 improves annotation placement, and IntelliJ IDEA 2026.1 will detect these issues automatically with inspections and quick-fixes.

15m read timeFrom blog.jetbrains.com
Post cover image
Table of contents
Entity class designMutabilityAccess typesNull safety and default valuesAnnotation placementIntelliJ IDEA to the rescue!About the author

Sort: