---
title: "How to Avoid Common Pitfalls With JPA and Kotlin"
url: https://daily.dev/posts/how-to-avoid-common-pitfalls-with-jpa-and-kotlin-hgchpvpwb
source_url: https://blog.jetbrains.com/idea/2026/01/how-to-avoid-common-pitfalls-with-jpa-and-kotlin/
type: article
source: "Kotlin"
published: 2026-01-20T18:49:15.012Z
updated: 2026-03-15T03:29:22.014Z
tags: ["devtools", "java", "kotlin", "spring"]
reading_time: 15
upvotes: 1
comments: 0
language: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# How to Avoid Common Pitfalls With JPA and Kotlin

**[Kotlin](https://daily.dev/sources/kotlin)** · 15 min read · 1 upvotes · 0 comments

## Summary

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.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://blog.jetbrains.com/idea/2026/01/how-to-avoid-common-pitfalls-with-jpa-and-kotlin/>

## Similar posts on daily.dev

- [Using Spring Data JDBC With Kotlin](https://daily.dev/posts/using-spring-data-jdbc-with-kotlin-jtkj8jwli) · JetBrains · 0 upvotes · 0 comments
- [Improved Annotation Handling in Kotlin 2.2: Less Boilerplate, Fewer Surprises](https://daily.dev/posts/improved-annotation-handling-in-kotlin-2-2-less-boilerplate-fewer-surprises-7d7giumef) · JetBrains · 2 upvotes · 0 comments
- [Null-Safe applications with Spring Boot 4](https://daily.dev/posts/null-safe-applications-with-spring-boot-4-ufnxqhfid) · Spring · 132 upvotes · 0 comments

---

Tags: [#devtools](https://daily.dev/tags/devtools), [#java](https://daily.dev/tags/java), [#kotlin](https://daily.dev/tags/kotlin), [#spring](https://daily.dev/tags/spring)

[View this post on daily.dev](https://daily.dev/posts/how-to-avoid-common-pitfalls-with-jpa-and-kotlin-hgchpvpwb)
