Quick revision
The short answer
I would frame it as a choice by workload rather than one tool for everything. ORMs such as JPA pay off for rich domain writes and remove boilerplate, but hide the SQL and need real expertise to avoid performance problems; SQL-first tools such as JdbcClient, jOOQ or MyBatis make every query explicit and predictable, which suits read-heavy and reporting work. A mixed standard, JPA for aggregates and SQL-first for reads, is common and usually right, and the decision must also weigh hiring and skills and the long-term costs of upgrades, licences and tool maintenance.
What to remember
In this answer, we framed the ORM versus SQL-first decision by workload. JPA helps rich domain writes and removes boilerplate but hides SQL and needs expertise; SQL-first tools make queries explicit and fit read-heavy and reporting work. We weighed hiring and skills and long-term costs such as the javax to jakarta move, Hibernate majors, licences and tool maintenance, and arrived at a mixed standard, JPA for aggregates and one SQL-first tool for reads, with rules, a reference service and a review date.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
I would frame it as a choice by workload rather than one tool for everything. ORMs such as JPA pay off for rich domain writes and remove boilerplate, but hide the SQL and need real expertise to avoid performance problems; SQL-first tools such as JdbcClient, jOOQ or MyBatis make every query explicit and predictable, which suits read-heavy and reporting work. A mixed standard, JPA for aggregates and SQL-first for reads, is common and usually right, and the decision must also weigh hiring and skills and the long-term costs of upgrades, licences and tool maintenance.
Why this question is asked
A ten-year standard for data access affects every service, every new hire and every upgrade the company will do. Framed badly, as JPA versus SQL, it becomes a debate between camps that each have war stories. Framed well, it becomes a decision about which workloads we have and what each tool costs over time. Interviewers ask this to see whether a senior leader can structure a contested decision, bring evidence and leave room for change. In this answer, we will set out the question, look at what ORMs and SQL-first tools are each good and bad at, consider people and skills, add the long-term costs, and arrive at a mixed standard with the rules that make it workable.
1Framing the Question Correctly
The first move is to stop asking which tool is better and ask what kinds of data access we do. Most companies have two broad workloads. Commands change a small cluster of related data, an aggregate such as an order with its lines, under business rules. Queries read and shape data for screens, APIs, exports and reports, often joining many tables and returning many rows. The two have different needs, and the tools fit them differently.
We then collect evidence from our own systems: how many queries are native already, where our performance incidents came from, how much time upgrades took. A decision backed by our own incident history is easier to accept than one based on opinion.
2What an ORM Gives and What It Costs
JPA with Hibernate maps tables to entities and manages their state. For writes this is a real advantage: we load an aggregate, call methods that enforce its rules, and the ORM writes the changes with dirty checking, optimistic locking and cascades. There is little boilerplate, and the domain model reads like the business.
The cost is that the SQL is hidden. Lazy loading, N+1 queries, flush timing, the persistence context and fetch plans are easy to misunderstand, and the problems appear in production rather than in code review. An ORM in the hands of a team that knows it well is productive; in the hands of a team that treats it as magic, it is the most common source of database performance incidents.
3What SQL-First Tools Give and What They Cost
SQL-first tools put the SQL in front of us. JdbcClient in Spring Framework 6.1 and later is a light fluent API over JDBC; jOOQ generates Java types from the schema and gives type-safe SQL; MyBatis maps SQL statements kept in XML or annotations to objects. Each makes the query explicit: what we write is what runs, which makes performance predictable and reviewable. They handle reporting features such as window functions and CTEs naturally.
The cost is that writes of rich aggregates need more code: we track what changed ourselves, write optimistic locking by hand and map nested structures explicitly. jOOQ's commercial editions also cost licence fees for some commercial databases, and generated code must be regenerated with schema changes.
4People, Skills and Long-Term Costs
Hiring matters for a ten-year decision. JPA is the most widely known Java persistence technology, so most candidates list it, but many understand it only at the surface, which is how ORM performance problems keep appearing. SQL skills are also widespread and transfer across languages. Whatever we choose, we must budget for training: an ORM standard without ORM expertise is the worst combination.
The long-term costs are easy to forget at decision time. ORMs bring major upgrades: the move from javax to jakarta packages, Hibernate 5 to 6 with its new query engine and changed behaviours, and 6 to 7 for Jakarta Persistence 3.2. Each takes real effort across many services. SQL-first tools have upgrades too, usually smaller, but jOOQ ties us to code generation and possibly licences, and MyBatis to its XML mappings. Every tool we standardise on is a tool we must maintain, document and teach for ten years, so the fewer we allow, the better, as long as each workload is served well.
| Factor | JPA / Hibernate | SQL-first (JdbcClient, jOOQ, MyBatis) |
|---|---|---|
| Rich domain writes | strong: dirty checking, locking, cascades | more code, manual change tracking |
| Reads, reports, exports | possible, easy to over-fetch | strong: explicit, predictable SQL |
| Performance predictability | needs expertise to avoid N+1, flush surprises | what you write is what runs |
| Hiring | widely known, often misunderstood | SQL widely known, tools less so |
| Long-term cost | major upgrades (javax to jakarta, Hibernate majors) | codegen, possible licences, mapping upkeep |
5A Mixed Standard and How to Make It Work
For most companies, the answer is a mixed standard by workload: JPA for aggregates and commands, a SQL-first tool for reads, reports and bulk work. This is common in practice and it plays to each tool's strength. Within one service both can coexist on the same DataSource and transaction manager, so a command and a query in the same request share a transaction where needed.
A mixed standard needs rules, or it becomes no standard. We pick exactly one SQL-first tool for the company, for example JdbcClient for simplicity or jOOQ where type safety across a large schema pays off, so knowledge is shared. Entities stay inside the service layer. We provide a reference service, a shared starter with logging and statement counting, and training for both. And we write the decision down as a record with a review date, for example every two years, so it can change when the tools or our needs change rather than when someone gets frustrated.
- Does it change an aggregate under business rules?YesJPA entities and repositoriesNoIt is a read or bulk operation
- Simple read of one entity's fields?YesJPA projection is fineNoUse the standard SQL-first tool
- Bulk load or large exportSQL-first or the database's bulk path
- Review the decision record every two yearstools and needs change
4 steps in order. Play them, or step through them one at a time.
6Follow-up questions
Why not standardise on SQL-first only, to keep things simple?
That can work for companies whose domain is mostly reads and simple writes. For rich domains with many rules, writing change tracking, optimistic locking and aggregate mapping by hand recreates a small ORM in every service. The mixed standard avoids that while keeping reads explicit.
How do you prevent a mixed standard from becoming chaos?
Limit it to two tools, one ORM and one SQL-first, with clear rules about which workload uses which. A reference service, a shared starter and code review checks keep services consistent.
What evidence would change your recommendation?
If incidents show that most of our database problems come from ORM misuse despite training, I would move more reads to SQL-first. If teams spend much of their time on hand-written persistence for complex aggregates, I would lean more on JPA.
7Conclusion
In this answer, we framed the ORM versus SQL-first decision by workload. JPA helps rich domain writes and removes boilerplate but hides SQL and needs expertise; SQL-first tools make queries explicit and fit read-heavy and reporting work. We weighed hiring and skills and long-term costs such as the javax to jakarta move, Hibernate majors, licences and tool maintenance, and arrived at a mixed standard, JPA for aggregates and one SQL-first tool for reads, with rules, a reference service and a review date.
Open with
I would not frame it as JPA versus SQL, but by workload. Most of our data access is either commands that change an aggregate under business rules, or reads that shape data for screens, APIs and reports.
Then, if they want more
JPA is strong for the first: you load the aggregate, call methods that enforce rules, and dirty checking, optimistic locking and cascades do the rest with little boilerplate. Its cost is that SQL is hidden, and without real expertise you get N+1 queries and flush surprises in production.
SQL-first tools like JdbcClient, jOOQ or MyBatis make every query explicit and predictable, which fits reads, reports and bulk work, but rich writes need more manual code. Then I would add people and long-term costs. JPA is widely known but often misunderstood, so any choice needs training.
ORMs bring big upgrades, like javax to jakarta and Hibernate 5 to 6, while SQL-first tools bring code generation, mapping upkeep and sometimes licences, as with jOOQ on commercial databases.
My recommendation would usually be a mixed standard: JPA for aggregates, exactly one SQL-first tool for reads and bulk, entities kept inside services, a reference service and shared starter, and a decision record reviewed every two years against our own incident and upgrade data.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Hibernate 5, Spring Framework 6
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Spring Data JPA reference, Hibernate ORM documentation, Spring Framework reference, Transaction management
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "You are asked whether your company should standardise on ORM-based data access (JPA) or...": https://scrivio-interview-library.netlify.app/databases/jpa-queries/f76e92e7e5/