{ "title": "Why I Stopped Using @Data in JPA Entities"

Day 26. I stopped using @Data in my JPA entities. Not because it doesn't work. Because it was breaking things I didn’t understand. I used to write this: // ❌ Looks clean — hides real problems @Data @Entity public class User { @Id private Long id; @OneToMany(mappedBy = "user") private List<Order> orders; } Looks clean. Less code. Everything auto-generated. Until it didn’t. Here’s what actually happens: → toString() triggers lazy loading → Infinite recursion in bidirectional relationships → Unexpected database queries → Hard-to-debug logs That’s when it clicked. @Data is not made for entities. It generates: → equals() → hashCode() → toString() And those methods don’t play well with JPA proxies and relationships. So I changed it. (see implementation below 👇) What I learned: → Lombok is powerful — but not always safe → Entities are not simple POJOs → Generated methods can silently break your system The hard truth: → @Data works in tutorials → It fails in real systems → Most developers don’t notice until production Writing less code is easy. Writing safe code is what makes you a backend developer. Are you still using @Data in entities? 👇 #SpringBoot #Java #Hibernate #BackendDevelopment #CleanCode #JavaDeveloper

  • text

Hot take: @Data is one of the most dangerous annotations in Hibernate. Not because it’s wrong — but because it hides complexity you need to understand.

To view or add a comment, sign in

Explore content categories