Quick revision
The short answer
Past shifts such as javax to jakarta were expensive mainly where persistence APIs had leaked through the whole code base, so the plan is to keep them contained: persistence types live only in a data access layer per service, every service stays on supported versions so each upgrade is small, and data access tests plus automated migration tooling such as OpenRewrite make the mechanical part cheap. We watch standards such as Jakarta Data and adopt them only where they bring clear value, service by service.
What to remember
In this answer, we saw that earlier persistence shifts cost the most where the API was spread through the code and where services had fallen far behind. The plan keeps persistence APIs inside a data access layer enforced by architecture tests, keeps every service on supported versions so upgrades stay small, uses OpenRewrite and strong data access tests for the mechanical part, and treats new standards like Jakarta Data as candidates to pilot when they bring clear value, not as obligations.
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.
Past shifts such as javax to jakarta were expensive mainly where persistence APIs had leaked through the whole code base, so the plan is to keep them contained: persistence types live only in a data access layer per service, every service stays on supported versions so each upgrade is small, and data access tests plus automated migration tooling such as OpenRewrite make the mechanical part cheap. We watch standards such as Jakarta Data and adopt them only where they bring clear value, service by service.
Why this question is asked
With 200 services on JPA, a change in the persistence API is not a refactoring task but a programme that can tie up every team for a year. Interviewers ask this at principal level to see whether we learn from history and turn it into structure, rather than predicting which technology wins. The goal is not to guess the next shift but to make any shift cheap. In this answer, we will look at what made earlier shifts expensive, how to contain persistence APIs, why staying current is the cheapest insurance, how tooling and tests carry the mechanical work, and how to judge new standards like Jakarta Data.
1What Made Past Shifts Expensive
Each previous shift changed the API that code touched directly. Moving from EJB 2 entity beans to Hibernate and then JPA meant rewriting data access completely. The move from javax.persistence to jakarta.persistence, which came with Jakarta EE 9, changed no behaviour at all; it only renamed packages. Yet it took many organisations a year or more, because the old package names appeared in entities, services, controllers, test utilities, shared libraries and third-party dependencies, all of which had to move at the same time.
So the cost of a shift is roughly the number of places that depend on the changing API, multiplied by the number of versions a service is behind. A service whose controllers catch PersistenceException, whose domain classes call EntityManager, and which sits on a version from five years ago pays the most. A service that touches the API in one package and upgrades every few months pays the least.
2Contain Persistence Inside a Data Access Layer
The structural answer is a boundary. Each service keeps JPA entities, repositories and EntityManager use inside a data access layer, an adapter package behind interfaces that the domain owns. Web code and domain logic depend on those interfaces and on plain domain types, never on jakarta.persistence or Hibernate classes. Then a future change in the persistence API touches one package per service instead of the whole service.
We do not need to be dogmatic. Many services map JPA entities directly as their domain model, and duplicating every class would cost more than it saves. The rule that matters is that persistence exceptions, EntityManager, Hibernate-specific types and query APIs do not leak into controllers and business services. ArchUnit tests can enforce exactly that, which turns a guideline into a build failure.
- Web layercontrollers, DTOs; no persistence imports
- Application and domainuse cases, rules; depend on repository interfaces
- Data access layerentities, JPA repositories,
EntityManager, Hibernate - Databaseschema owned by migrations
4 layers, from the top down. Step through them one at a time.
A future API change is absorbed in one layer per service.
3Stay on Supported Versions Continuously
The second lesson is that big migrations are usually many small ones that were postponed. A service that moves from Spring Boot 3.4 to 3.5 deals with a short list of changes. A service that jumps from Boot 2.7 to 4.0 also takes on javax to jakarta, Hibernate 5 to 7 and Java 11 to 25 in one go, and every failure has many possible causes.
So we set a policy: every service stays within the supported versions of its platform, for example the current and previous Spring Boot minor lines, and a shared platform bill of materials moves first. Automated dependency updates open pull requests, and a dashboard shows each service's lag. Upgrading becomes routine work of a few hours per service per quarter, which is far cheaper than a forced programme later.
4Let Tools Do the Mechanical Work, and Let Tests Prove It
Most of an API shift is mechanical: renamed packages, renamed methods, changed property names. OpenRewrite recipes, which rewrite source code from a description of the change, handled much of the javax to jakarta move and many Spring Boot upgrades. With 200 services, we run the recipe centrally, open pull requests automatically and let each team review.
Tooling is only safe when tests show that behaviour did not change. Data access is the part most likely to change silently, because a new Hibernate version can generate different SQL, flush at different times or map a type differently. So every service keeps integration tests for its repositories against the real database engine, for example with Testcontainers, covering the queries it relies on, plus statement count checks on the hot paths. With those in place, a recipe plus a green build is strong evidence; without them, every upgrade is a gamble.
5Judging New Standards Such as Jakarta Data
Jakarta Data, part of Jakarta EE 11, defines repository interfaces in the standard, similar in spirit to Spring Data. It is worth watching, and it may matter if we ever leave Spring or want a vendor-neutral repository API. But adopting it across 200 services because it is new would be a self-inflicted shift. We would let one or two teams try it in a new service, write down what it costs and what it gives, and adopt it more widely only if the value is clear, for example less code or a portability need we actually have.
Here is how we would decide for any new persistence standard. If it removes real pain we can measure, we pilot it; if it only renames what we already have, we wait until our frameworks require it, and the containment from the earlier sections keeps that future move small.
- Does it solve a problem we measure today?Yespilot it in one new serviceNowait; keep it on the watch list
- Did the pilot show clear value?Yeswrite a migration recipe and guideNorecord why, revisit next year
- Adopt service by serviceinside the data access layer only
3 steps in order. Play them, or step through them one at a time.
6Follow-up questions
Is it worth wrapping JPA in our own abstraction to be safe?
Usually not a full abstraction, because a home-grown persistence API becomes a second thing to maintain and still leaks. Containment is enough: JPA stays in the data access layer, and the rest of the code depends on repository interfaces the domain owns. That gives most of the protection at a fraction of the cost.
How do we measure whether we are ready for the next shift?
Track two numbers per service: how many versions behind the supported baseline it is, and how many classes outside the data access layer import persistence packages. Both should trend towards zero, and both can be collected automatically in the build.
Who owns the upgrades in such an organisation?
A platform team owns the shared bill of materials, the OpenRewrite recipes and the upgrade dashboard, and moves first. Service teams own applying the upgrade and keeping their data access tests strong. Splitting it this way keeps the expertise central and the work distributed.
7Conclusion
In this answer, we saw that earlier persistence shifts cost the most where the API was spread through the code and where services had fallen far behind. The plan keeps persistence APIs inside a data access layer enforced by architecture tests, keeps every service on supported versions so upgrades stay small, uses OpenRewrite and strong data access tests for the mechanical part, and treats new standards like Jakarta Data as candidates to pilot when they bring clear value, not as obligations.
Open with
I would start from what actually made the past shifts expensive. The javax to jakarta move changed no behaviour, only package names, and it still took organisations a year, because persistence types were everywhere: in controllers, domain services, shared libraries and tests, and many services were several versions behind.
Then, if they want more
So my plan has three parts. First, containment: in each service, JPA entities, repositories, EntityManager and Hibernate types stay in a data access layer behind interfaces the domain owns, and an ArchUnit rule fails the build if web or domain code imports jakarta.persistence or org.hibernate. Then the next API change touches one package per service.
Second, stay current: a platform bill of materials moves first, automated dependency updates keep every service within the supported Spring Boot and Hibernate lines, and a dashboard shows who is lagging. Small quarterly upgrades are much cheaper than one forced jump.
Third, tooling and tests: OpenRewrite recipes do the mechanical rewrites centrally, and each service keeps repository integration tests against the real database with Testcontainers, plus statement count checks on hot paths, so a green build after a recipe really means something.
For Jakarta Data and similar standards, I would pilot them in a new service, measure the benefit and only adopt them widely when the value is clear.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Hibernate 5, Jakarta EE 11, Jakarta EE 9, Java 11
- 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 "Java persistence has moved through JDBC, EJB entity beans, Hibernate, JPA, javax to...": https://scrivio-interview-library.netlify.app/databases/jpa-fundamentals/786cac9860/