Home United States USA — software Lombok and JPA: What Could Go Wrong?

Lombok and JPA: What Could Go Wrong?

212
0
SHARE

This article shows the most common issues you may face using Lombok with JPA entities.
Join the DZone community and get the full member experience. Lombok is a great tool that makes your Java code concise and clean. However, there are a few things to consider when using it with JPA. In this article, we’ll look at how the misuse of Lombok can hurt the performance of JPA applications or even crash them, and how to avoid that but still gain the benefits of using Lombok. We develop JPA Buddy – a plugin for IntelliJ IDEA designed to make the use of JPA easier. Before writing a single line of code for it, we went through a ton of projects on GitHub to understand how people work with JPA. Turns out, a lot of them use Lombok for their entities. It is absolutely fine to use Lombok in your JPA projects, but it has some caveats. Analyzing the projects, we see people stumble into the same pitfalls over and over again. This is why we introduced a number of code inspections for Lombok to JPA Buddy. This article shows the most common issues you may face using Lombok with JPA entities. Entity classes often get annotated with @EqualsAndHashCode or @Data. The documentation of @EqualsAndHashCode states: By default, it’ll use all non-static, non-transient fields, but you can modify which fields are used (and even specify that the output of various methods is to be used) by marking type members with @EqualsAndHashCode. Include or @EqualsAndHashCode. Exclude. Equals()/hashCode() implementation for JPA entities is a sensitive subject.

Continue reading...