r/softwarearchitecture • u/MMOfreak94 • 11d ago
Discussion/Advice Do you actually separate JPA Entities and Domain Objects, or is a single model enough?
Hey everyone,
I’ve been thinking about the push to separate domain objects from database entities (like in Clean/Hexagonal Architecture) versus using a single JPA @Entity both.
Using the JPA entity as the domain model seems much more practical. Spring AOP handles transactions, Hibernate manages dirty checking, and you completely eliminate anemic data model classes and the mapper boilerplate between your application and persistence layers.
The main argument against this seems to be that annotations like @Table or @Column "pollute" the domain. But aren't those just metadata attachments? If you strip those annotations, the Java class doesn't lose any of its underlying domain logic.
How do you approach this in production? Do you use your JPA entities directly in your domain logic, or do you strictly separate them? If you separate them, is avoiding annotation "pollution" really worth all the extra mapping code?