Lombok vs Records vs Manual Code and How to Decide
Choose between Lombok, records and hand written classes by looking at the type: value objects, JPA entities, builders and mutable beans each have a best fit.

Lombok, records and hand-written classes all solve the same irritation, which is how much text a plain Java data class needs. Since records arrived in Java 16, the question is no longer whether to use Lombok everywhere but which of the three suits each kind of type. The answer is different for a DTO, a JPA entity and a class with behaviour. This post gives a decision per type, with the reasons, using JDK 25, Lombok 1.18 and Hibernate 7.
What each option really gives you
A record declares its components once and the compiler generates the canonical constructor, the accessors, equals, hashCode and toString. Its fields are final and the class cannot be extended.
public record Money(BigDecimal amount, String currency) {
public Money {
Objects.requireNonNull(amount);
if (currency.length() != 3) throw new IllegalArgumentException(currency);
}
}Lombok is an annotation processor that rewrites your class during compilation. @Getter, @Setter, @Builder, @Data and @Slf4j add code you never see in the source. It works on mutable classes, which records cannot be, and it generates things records do not, such as builders and loggers.
A hand-written class has no magic and no limits, and costs lines. The IDE generates constructors, accessors and equals in a few keystrokes, so the real cost is not typing but reading and keeping them correct as the class changes.
Value objects and DTOs: records
For an immutable value that is defined by its contents, a record is the best default. It is shorter than Lombok's @Value, needs no build plugin, and works with the language: pattern matching can deconstruct it, and switch can match on its components. Jackson, Hibernate's projection support and Spring MVC all handle records directly, as shown in DTO projections with records.
The limits are real. A record cannot extend a class, cannot have non-final instance fields, and exposes its components as its public shape. Adding a field later changes the constructor, which breaks every caller. For a response type that gains optional fields over time, add a static factory or a builder rather than telling callers to pass null.
JPA entities: hand-written
An entity cannot be a record. Hibernate needs a no-argument constructor and mutable state so that it can set fields when it loads a row, and it creates proxy subclasses for lazy loading, which a final class forbids. The mapping rules are in entity mapping.
The tempting shortcut is @Data on an entity, and it causes bugs. @Data generates equals and hashCode over every field, including lazy associations, so calling hashCode on an entity can trigger a query, or a LazyInitializationException outside a transaction. It also generates a toString that walks the relationships, which can recurse forever on a bidirectional association. Hand-write equals and hashCode based on the identifier or a natural key. If you want less typing, use @Getter and @Setter on the entity and nothing else.
Builders: the case Lombok still wins
A class with eight optional fields needs a builder, and records do not generate one. Writing a builder by hand is thirty lines of mechanical code. @Builder on the class or a constructor removes it.
@Builder
public record Query(String text, int page, int size, List<String> tags) {}
var q = Query.builder().text("jdbc").page(2).size(20).build();@Builder works on records, so you can combine the two. This is the strongest remaining argument for keeping Lombok: it does one thing that nothing in the language does. If a project uses it only for @Builder, it is cheap to keep, and to remove later with the delombok step described in removing Lombok.
Loggers and the small stuff
@Slf4j replaces a one-line field declaration. It is harmless, and not worth a dependency on its own. @RequiredArgsConstructor on a Spring bean saves a constructor, but with one constructor injection is already concise, and the explicit constructor makes dependencies visible in review. @Slf4j alone is not a reason to add Lombok to a project that does not have it.
A decision table
| Type | Choose | Reason |
|---|---|---|
| Immutable value, DTO, API response | Record | Shortest, built into the language |
| Value with many optional fields | Record plus @Builder or a hand-written builder | Records have no builder |
| JPA entity | Hand-written, @Getter and @Setter at most | Needs mutability and a safe equals |
| Class with behaviour and invariants | Hand-written | Constructor and methods are the design |
| Spring bean with injected collaborators | Hand-written constructor | One line each, explicit |
| Logger field | @Slf4j if Lombok is already present, else a static field | Not worth a dependency |
The costs, honestly stated
Lombok has a tooling cost. It hooks into javac internals, so each new JDK release can break an old Lombok version, and the build plugin, the IDE plugin and the annotation processor path must all agree. Code that uses it reads differently from the source file it compiles to, so stack traces and debugger sessions point at generated lines. Static analysis and some code generators see the class before Lombok has run.
Records have a design cost. Exposing the components as the public API is a decision, and renaming one is a breaking change. Hand-written classes have the cost of lines, but those lines are visible, debuggable and never surprising. Compare the tooling story with other options in Lombok versus Immutables and records.
Migrating an existing codebase
Do not convert everything at once. Convert DTOs and value classes when you next touch them, because each is a self-contained change with a compiler to check it. Leave entities alone. Keep one lombok.config at the project root with lombok.addLombokGeneratedAnnotation = true, so coverage tools ignore generated code, and add lombok.anyConstructor.addConstructorProperties = false unless something still reads the legacy annotation. When the last @Data is gone, delete the dependency and let the build prove nothing needed it.
Pick a default and write it down
The worst outcome is not any one choice but a package where one DTO is a record, the next is a @Value class and the third is hand-written, with no reason for the difference. Pick a default for each kind of type, put it in the contributing guide, and let a reviewer cite it. A reasonable default for a new project on JDK 21 or later is records for values, hand-written entities, and no Lombok unless a builder is needed.
The language feature is specified in JEP 395, and the annotation list with its caveats is in the Lombok feature documentation.


