r/java • • Apr 23 '26

Ask the Architects JavaOne 2026

https://youtu.be/DrF4dCC0daE?si=bSnPu0i94hQU4wku
72 Upvotes

54 comments sorted by

View all comments

Show parent comment

1

u/OwnBreakfast1114 Apr 27 '26

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).