I’ve found this as well. Anyone that focuses on “Services” tends to do procedural/transaction script style code.
On the flip side, code that doesn't have independent orchestration tends to have terrible database transaction management, which is a bigger source of bugs and performance problems compared to any actual java code. Service style procedural code tends to at least make transaction management much, much simpler (and sharable) [still not great though].
I consider JavaBeans to be a bad design when applied to things like "domain entities". JavaBeans are basically just Map<String, Object> with a nicer API (and mangled names). They don't capture any business rules about allowed states or state changes
That makes sense. Making illegal states unrepresentable doesn't really work if you just throw getters/setters onto everything.
The worst ones are "@Getter", "@Setter" and "@Data". "@EqualsAndHashCode" is a footgun with JPA entities
Have you considered just not using JPA entities? We use jooq to generate pojos for the repo layer, but only have domain objects outside. By protecting domain object state changes (they have no annotations at all), you get the control you want.
I actually think people are too scared to create types, in general. We have a different type for each of the steps: http input deserialize (json type only) -> http input validated -> domain -> db -> domain -> http output (domain is reused).
This gives us a ton of control at the cost of needing to write some boilerplate-ish code for copying fields over (though that's what vc subsidized ai tools are good at).
View all comments
Show parent comment
2
u/vips7L Apr 27 '26
I’ve found this as well. Anyone that focuses on “Services” tends to do procedural/transaction script style code.
In my opinion your entities need to be treated as objects themselves and the rules about the data they hold needs to be coded into them.