Scrivio Interview library
LeadershipAdvanced6 min read · updated 12 November 2026

Some teams want to use only JdbcClient and plain SQL instead of JPA for all new services. How would you evaluate allowing this as an approved option?

I would evaluate it as a trade-off rather than a preference: plain SQL with JdbcClient gives predictable queries and fewer hidden behaviours, at the cost of more mapping code, and it fits services with simple aggregates or read-heavy workloads better than those with rich domain writes. If we allow it, it must meet the same standards as JPA services: schema migrations, clear transaction boundaries, tests against the real database and statement metrics. Spring Data JDBC is a middle option worth offering, and I would approve plain SQL as a documented option, then compare defect and delivery data over time.

Why this question is asked

Platform standards exist so that teams do not each rediscover the same lessons, but a standard that cannot change becomes a reason for good engineers to leave. When teams ask to drop JPA, they usually have real reasons: surprising lazy-loading queries, N+1 problems, flush timing, and hours spent debugging what Hibernate decided to do. Interviewers ask this at senior levels to see how we evaluate a request to widen a standard. In this answer, we will look at what each approach really costs, decide where plain SQL fits, set the standards an approved option must meet, consider Spring Data JDBC as a middle path, and plan how to approve it and learn from the results.

1Why Teams Ask for It

JPA does a lot for us, but much of it is invisible. A getter on a lazy association runs a query. A changed field becomes an UPDATE at flush time, which may be long after the line that changed it. A collection mapped the wrong way issues one query per row. These behaviours are documented and manageable, but they surprise people regularly, and diagnosing them requires knowing Hibernate well.

With JdbcClient, the SQL we write is the SQL that runs, at the moment we call it. Many engineers find that easier to reason about, review and tune, especially as more of them know SQL well and fewer have deep Hibernate experience. Those are legitimate arguments, and they deserve an evaluation rather than a reflexive no.

2What Each Approach Really Costs

Plain SQL is not free. Every query needs mapping code, which JdbcClient's query(Class) reduces but does not remove for joins and nested structures. Writing an aggregate with child collections means deciding ourselves which rows to insert, update or delete, work that JPA's cascades and dirty checking do for us. Optimistic locking, auditing columns and soft deletes, which JPA handles with annotations, become conventions we must implement and review.

JPA vs plain SQL with JdbcClient
ConcernJPA and HibernateJdbcClient and SQL
Queries that rungenerated; can surpriseexactly what we wrote
Mapping codeannotations, little codemore code, explicit
Rich aggregate writescascades, dirty checkinghand-written insert/update/delete
Reports and complex readsprojections or native SQLnatural fit
Hidden behaviourlazy loading, flush timing, N+1very little
Locking, auditing, soft deleteannotations and listenersconventions to implement
Skills neededHibernate depthsolid SQL
Neither column wins everywhere; the service's shape decides.

So the comparison depends heavily on the service's shape. For a service whose writes are simple and whose reads are complex, plain SQL often wins. For a service with a rich domain model, many entity relationships and complex write rules, JPA's machinery saves real code.

3Where Plain SQL Fits

From that comparison, plain SQL fits well in services with simple aggregates, such as a notification service that writes one row per message, and in read-heavy services, such as a reporting or search API that composes complex queries. It also fits services that rely on database features, such as PostgreSQL's JSONB operators, upserts or window functions, where JPA would mostly be used for native queries anyway.

It fits less well in services with deep domain models: an order with lines, discounts, shipments and status rules, edited through many use cases. There, hand-writing the persistence of every change is a lot of code and a lot of chances to forget a child row. I would not forbid plain SQL there, but the design note should show how the team will handle aggregate writes and optimistic locking.

4The Standards an Approved Option Must Meet

Allowing a second option must not mean lowering the bar. Whatever the data access style, a service must manage its schema with migrations, Flyway or Liquibase, in version control. Transactions must be declared at the service layer with @Transactional, with the same rules about boundaries and external calls. Tests must run against the real database engine and version, typically with Testcontainers, because plain SQL errors only show at runtime.

Observability must be equal too: statement counts and timings per query, slow query logging, and connection pool metrics, so we can compare the options fairly. And the safety rules stay: values are always bound, never concatenated, with static analysis in CI to enforce it. Writing these requirements down turns plain SQL from a team preference into a supported platform option.

5Spring Data JDBC as a Middle Option

Spring Data JDBC sits between the two. It gives repositories and aggregate mapping like Spring Data JPA, but with no lazy loading, no persistence context and no dirty checking. Loading an aggregate loads all of it; saving an aggregate writes all of it, deleting and reinserting child rows if needed. Custom SQL is easy to add with @Query or by dropping to JdbcClient.

For many teams that want predictability without writing all mapping by hand, it is the sweet spot, and it fits Domain-Driven Design's idea of small aggregates saved as a unit. Its costs are that large child collections are rewritten on save and that some JPA conveniences are missing, so check its feature set for your use case. Offering it alongside plain JdbcClient gives teams a gradient instead of a binary choice.

6Approving It and Learning From the Results

I would approve plain SQL as a documented option with clear guidance on where it fits, the standards above, a reference service and a short design note template. Then I would measure. For services on each style, we track defects related to data access, incidents and their time to diagnose, lead time for changes, and the share of time spent on persistence code, comparing services of similar size.

After a year or so, the data tells us whether the option is doing well, needs better guidance, or should be narrowed. If plain SQL services show fewer persistence incidents and similar delivery speed, we might even recommend it for more service types. Whatever the outcome, the decision will rest on our own evidence rather than on opinions from either side.

Step throughEvaluating a new data-access option
  1. Collect the teams' reasonspain points with JPA, examples
  2. Compare costs for each service shapesimple, read-heavy, rich domain
  3. Define the standardsmigrations, transactions, tests, metrics, binding
  4. Approve as a documented optionguidance, reference service, design note
  5. Measure defects and deliverycompare similar services over a year
  6. Data supports it?fewer incidents, similar speed
    YesKeep or widen the optionNoNarrow the guidance

6 steps in order. Play them, or step through them one at a time.

The option is approved with standards and then judged on evidence.

7Follow-up questions

Would you let a single service mix JPA and JdbcClient?

Yes, and many services should: JPA for aggregate writes and JdbcClient for reports and bulk operations is a well-understood pattern. Both share the same transaction under JpaTransactionManager. The guidance just needs to cover flushing before JDBC reads and refreshing or clearing after JDBC writes.

What about type safety with plain SQL?

Plain SQL strings are checked only at runtime, which is why tests against the real database are mandatory for this option. Teams that want compile-time checking can use jOOQ, which generates classes from the schema; that could be a third documented option if there is demand, with its own licensing considerations for commercial databases.

How do you prevent the option from fragmenting the platform?

By keeping everything around it the same: the same starters, migrations, test setup, metrics and security rules, and a reference implementation teams can copy. Fragmentation hurts when each team invents its own way; a small number of documented, supported options with shared tooling does not.

8Conclusion

In this answer, we saw that requests to use only JdbcClient come from real pain with JPA's hidden behaviours, and that plain SQL trades predictability for more mapping code. It fits simple aggregates and read-heavy services better than rich domain writes. If we approve it, it must meet the same standards for migrations, transactions, real-database tests, metrics and bound parameters. Spring Data JDBC offers a middle path, and approving plain SQL as a documented option, then comparing defect and delivery data over time, keeps the decision grounded in evidence.

What to say in the interviewAbout 90 seconds aloud

Open with

I would take the request seriously, because the reasons are usually real: lazy loading, N+1 queries, flush timing and other hidden behaviour that takes Hibernate depth to debug.

Then, if they want more

With JdbcClient, the SQL we write is the SQL that runs, which is easier to review and tune. The cost is more mapping code, and for rich aggregates we have to hand-write which child rows to insert, update or delete, plus things like optimistic locking and auditing that JPA gives us through annotations.

So I would say it fits services with simple aggregates and read-heavy or database-feature-heavy workloads, and fits less well in services with deep domain models.

If we allow it, it has to meet the same bar as everything else: Flyway or Liquibase migrations, @Transactional at the service layer, tests against the real database with Testcontainers because SQL errors only show at runtime, statement metrics and slow query logs, and bound parameters enforced by static analysis.

I would also offer Spring Data JDBC as a middle option, since it gives repositories and aggregate mapping without lazy loading or a persistence context. Then I would approve plain SQL as a documented option with a reference service and a design note template, and measure: data-access defects, incident diagnosis time and delivery speed for similar services on each style.

After a year, the data tells us whether to keep, widen or narrow it.

About this answer

Last updated
12 November 2026
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
java.sql, package documentation
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 "Some teams want to use only JdbcClient and plain SQL instead of JPA for all new...": https://scrivio-interview-library.netlify.app/databases/jdbc/374c7e708a/