Video in progress
Would you standardize JPA/Hibernate across all services in the company, or jOOQ/plain SQL? What criteria do you decide by?
I don't force a single standard. Hibernate pays off in services with a rich domain and lots of CRUD; in services with complex reporting, high-volume writes and work close to SQL, jOOQ or JDBC is better. What matters is that the team's experience and the observability tooling are the same.
📖 Answer
Answering this question with "Hibernate is good" or "ORMs are bad" is not a signal. I evaluate each service on a few dimensions.
Domain complexity. If there are lots of aggregates, invariants and state changes (an order, a contract, an application), Hibernate's dirty checking and unit of work cut the amount of code noticeably.
Query shape. If the service's main job is window functions, CTEs and complex aggregation, JPQL gets in the way and everything ends up as native queries anyway. In that case jOOQ gives you type-safe SQL.
Write volume. In an ingestion service that writes hundreds of millions of events a day, the persistence context is extra overhead.
The team. A team that knows Hibernate only "on the surface" loses a lot of time to N+1, LazyInitializationException and unexpected flushes. The price of an ORM is that you have to know it deeply.
In practice, I standardize these at the platform level:
- the migration tool (Flyway or Liquibase): one for everybody;
- the connection pool, timeouts and metrics (HikariCP + Micrometer);
- SQL logging and slow query monitoring.
The data access layer itself is a decision inside the service, but it is documented with an ADR. In many projects a hybrid is fine too: Hibernate on the write side, reports through JdbcClient or jOOQ, all under one transaction manager.
Sign up to mark studied questions and save your progress.