Kotlin data classes in Spring Boot 4 can silently break JPA entities
A developer compiled Kotlin data classes with and without the Kotlin compiler plugins and inspected the resulting bytecode alongside Spring and Hibernate loading code. The tests ran on Spring Boot 4.1.1, Hibernate 7.4.5, Jackson 3.1.5, Kotlin 2.3.21 and Java 21. Data classes suit configuration properties and request or response DTOs, since Spring uses the Kotlin primary constructor and applies defaults. Without the JPA and all-open plugins, however, entity classes are final, which disables lazy loading proxies and can trigger extra queries without warning. Missing no-arg constructors can also cause InstantiationException on first load. The recommended fix is to enable the jpa and all-open plugins, which start.spring.io configures by default.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in