Kotlin is great: it’s more concise and expressive than Java, it allows for safer code, and offers seamless interoperability with Java. The latter allows developers to migrate their projects to Kotlin without having to rewrite the entire codebase. Such migrations are one of the reasons why we might have to work with JPA in Kotlin. Picking JPA for a fresh Kotlin application also makes sense, as it is a mature technology familiar to the developers.

There is no JPA without entities, and defining them in Kotlin comes with some caveats. Let’s look at how to avoid the common pitfalls and make the most of using Kotlin. Spoiler alert: data classes are not the best option for entity classes.

This article will be mostly focused on Hibernate as it is undoubtedly the leader among all JPA implementations.

Source de l’article sur DZONE