After upgrading from Spring Boot 2.7 to 3.x, a build that used to pass can fail with package javax.persistence does not exist or The import javax.persistence cannot be resolved. This is a Jakarta migration issue, not a missing IDE plugin. Spring Boot 3 moved to Jakarta EE 10 and Jakarta Persistence 3.1, so the API now lives in jakarta.persistence and the old javax.persistence artifact is no longer brought in transitively. Spring Boot 3.0 also requires Java 17, so an old JDK can hide the real cause until you fix that first.

In short: point persistence imports at jakarta.persistence, let the Boot 3 starter bring in jakarta.persistence-api 3.1 and Hibernate 6, and remove the old javax.persistence-api jar. A reliable Jakarta migration fix is a sequence, not a global find-and-replace, so confirm the upgrade, repair the dependency graph, rewrite only the persistence imports, update persistence.xml and Hibernate settings, then deal with the errors that surface afterward. This guide follows that order and ends with a test that proves the persistence unit actually starts and round-trips an entity.

Table of Contents

  • Why the Import Breaks After the Upgrade
  • Step 1: Confirm the Upgrade and Find the Old API
  • Step 2: Fix Dependencies Before Imports
  • Step 3: Rewrite Persistence Imports Selectively
  • Step 4: Update persistence.xml and Hibernate Settings
  • Step 5: Clear the Follow-On Errors
  • Step 6: Verify With a Persistence Test
  • Conclusion

Why the Import Breaks After the Upgrade

JPA is a specification, and Hibernate is one of its implementations. The specification started life as the Java Persistence API under Java EE, was modeled on Hibernate, and later moved to the Eclipse Foundation as Jakarta Persistence. The interfaces and annotations stayed conceptually the same, but the package prefix changed from javax.persistence to jakarta.persistence when the specification moved to the Jakarta namespace. If you want the longer version of that relationship, this comparison of JPA and Hibernate explains how the specification and the provider divide responsibilities.

That history matters because annotations are Java types, not strings. @javax.persistence.Entity and @jakarta.persistence.Entity are different annotation types. A class carrying the old annotation compiles fine if an old jar is still on the classpath, but Hibernate 6 does not recognize it as an entity. This is why "fixing the import" can appear to work while the application still fails at startup.

Spring Boot 3.0 made the same move for every Jakarta EE dependency it manages. The Spring Boot 3.0 migration guide states that Boot 3.0 uses the JPA 3.1 specification, requires Java 17, and warns that older Java EE dependencies must no longer be used directly or transitively. It is also a good source for the other non-JPA changes you will hit during the upgrade, such as configuration property renames.

Step 1: Confirm the Upgrade and Find the Old API

Before changing imports, verify which Boot line the build actually resolves. Check the parent version in pom.xml or the Spring Boot plugin version in build.gradle. A project can look upgraded in one module while an older BOM still controls another module.

Then separate build failures from IDE noise:

./mvnw -q -DskipTests compile ./gradlew compileJava 

If the command-line build passes but the IDE still shows red imports, reimport the Maven or Gradle project and invalidate the IDE caches before changing dependencies. If the command-line build fails with package javax.persistence does not exist, the API is genuinely absent from the compile classpath.

Next, look for old persistence artifacts. In Maven:

./mvnw dependency:tree -Dincludes=javax.persistence:javax.persistence-api ./mvnw dependency:tree -Dincludes=org.hibernate.javax.persistence 

In Gradle:

./gradlew dependencyInsight --dependency javax.persistence --configuration runtimeClasspath 

The usual suspects are javax.persistence:javax.persistence-api:2.2, org.hibernate.javax.persistence:hibernate-jpa-2.1-api, Hibernate 5.x, and EclipseLink 2.x. Any of them can keep old javax.persistence imports compiling while the Jakarta provider ignores the annotations.

Step 2: Fix Dependencies Before Imports

Changing imports first produces a wall of red errors. Fix the dependency graph first, then the source code follows.

Component Spring Boot 2.7 Spring Boot 3.x What to do
JPA API javax.persistence:javax.persistence-api:2.2 jakarta.persistence:jakarta.persistence-api:3.1.x Remove the old API; let Boot manage the new one
ORM provider org.hibernate:hibernate-core:5.6.x org.hibernate.orm:hibernate-core:6.x Note the group ID change from org.hibernate to org.hibernate.orm
Starter spring-boot-starter-data-jpa:2.7.x spring-boot-starter-data-jpa:3.x Upgrade through the Boot parent or BOM
Validation javax.validation:validation-api jakarta.validation:jakarta.validation-api Migrate separately, after JPA compiles
Servlet javax.servlet:javax.servlet-api jakarta.servlet:jakarta.servlet-api Migrate separately, after JPA compiles

For most Spring Boot applications, the dependency fix is simply the starter:

<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> 

The Spring Boot reference for SQL databases lists Hibernate, Spring Data JPA, and Spring ORM as the starter's key dependencies, so you should not need to add jakarta.persistence-api yourself. Adding it manually with the wrong version is a common way to create a new mismatch.

If you manage persistence without the starter, use the Jakarta Persistence 3.1 API coordinates and a Hibernate 6.x core artifact. The Jakarta Persistence 3.1 release page lists jakarta.persistence:jakarta.persistence-api:3.1.0 and names Hibernate ORM 6.0.0.Final as a compatible implementation. Hibernate's introduction guide shows the matching provider coordinate as org.hibernate.orm:hibernate-core, which is the group ID change that trips up many upgrades from Hibernate 5.

Remove old javax.persistence declarations and exclusions rather than leaving both APIs in place. If a third-party library drags in the old API, exclude it at that dependency and upgrade the library. A global exclusion can hide a real requirement, so exclude narrowly and run the dependency check again.

Step 3: Rewrite Persistence Imports Selectively

Do not rename every javax import in the repository. Many javax packages are part of the JDK and are not affected by the Jakarta migration.

Old import Action for Boot 3
javax.persistence.* Change to jakarta.persistence.*
javax.validation.* Change to jakarta.validation.*, but handle it as a separate validation migration
javax.servlet.* Change to jakarta.servlet.*, but handle it as a separate web migration
javax.transaction.* Change to jakarta.transaction.*
javax.annotation.PostConstruct, PreDestroy, Resource Change to jakarta.annotation.*
javax.annotation.Nullable from JSR-305 Leave it alone; it is not a Jakarta EE annotation
javax.sql.*, javax.crypto.*, javax.net.*, javax.naming.* Leave them alone; they are JDK packages

The reason to keep persistence separate from validation and servlet work is diagnostic, not cosmetic. If you change all three namespaces in one commit and the application fails to start, you cannot tell whether the problem is an entity, a controller, or a validator. Get the persistence unit healthy first, then migrate the other APIs with their own dependency changes.

A Jakarta entity looks like this:

package com.example.orders; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; import jakarta.persistence.Table; @Entity @Table(name = "orders") public class Order { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; private String reference; protected Order() { } public Order(String reference) { this.reference = reference; } public Long getId() { return id; } public String getReference() { return reference; } } 

EntityManager code changes the same way. The Spring annotations around it do not:

package com.example.orders; import jakarta.persistence.EntityManager; import jakarta.persistence.PersistenceContext; import org.springframework.stereotype.Repository; @Repository public class OrderDao { @PersistenceContext private EntityManager entityManager; public Order find(Long id) { return entityManager.find(Order.class, id); } } 

Two related errors usually mean a missed import rather than a missing dependency. If EntityManagerFactory cannot be resolved, check for import javax.persistence.EntityManagerFactory; and replace it with jakarta.persistence.EntityManagerFactory. If @PersistenceContext is unresolved, the likely cause is javax.persistence.PersistenceContext in the import block. Spring's @Transactional from org.springframework.transaction.annotation is unchanged, so do not rename it just because persistence moved.

Finally, clean generated sources. Annotation processors can emit old imports into target/generated-sources or build/generated. If you use a JPA metamodel generator or Querydsl's annotation processor, upgrade it to a Jakarta-compatible version and run a clean build so stale generated classes do not survive the migration.

Step 4: Update persistence.xml and Hibernate Settings

If the project still has a src/main/resources/META-INF/persistence.xml, its namespace and schema location must move too. Jakarta Persistence 3.x defines new XSD namespaces for persistence.xml and orm.xml, and the Hibernate 6.0 migration guide notes that Hibernate can still read some Java EE names temporarily but logs a deprecation warning. Treat that compatibility as a migration aid, not a permanent configuration.

Descriptor Old namespace New namespace
persistence.xml http://xmlns.jcp.org/xml/ns/persistence https://jakarta.ee/xml/ns/persistence
orm.xml http://xmlns.jcp.org/xml/ns/persistence/orm https://jakarta.ee/xml/ns/persistence/orm

Older files may use http://java.sun.com/xml/ns/persistence; that also needs to change. Here is a working Jakarta-era descriptor:

<?xml version="1.0" encoding="UTF-8"?> <persistence xmlns="https://jakarta.ee/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://jakarta.ee/xml/ns/persistence https://jakarta.ee/xml/ns/persistence/persistence_3_0.xsd" version="3.0"> <persistence-unit name="orders" transaction-type="RESOURCE_LOCAL"> <class>com.example.orders.Order</class> </persistence-unit> </persistence> 

The version="3.0" in that descriptor is not a mistake even though Boot 3 uses JPA 3.1. The API version and the deployment descriptor schema version are separate things. At the time of writing, the 3.1 release publishes an orm_3_1.xsd for orm.xml, while Hibernate's current getting-started guide still shows persistence_3_0.xsd with version="3.0" for persistence.xml. Use a schema URL that actually exists and stays consistent with the version attribute; a copied persistence_3_1.xsd URL that returns 404 can produce IDE validation errors.

This minimal descriptor leaves the connection to Spring Boot, which supplies it through spring.datasource.*. If you keep JDBC URL, credential, or schema-generation properties in persistence.xml, translate their keys with the table below. And if the file is a leftover from a non-Boot setup while Boot already scans your entities, removing it avoids two competing sources of configuration.

Property keys inside the descriptor need the same treatment. Hibernate 6 renamed the JPA-standard settings from javax.persistence.* to jakarta.persistence.*:

Old property New property
javax.persistence.jdbc.url jakarta.persistence.jdbc.url
javax.persistence.jdbc.user jakarta.persistence.jdbc.user
javax.persistence.jdbc.password jakarta.persistence.jdbc.password
javax.persistence.schema-generation.database.action jakarta.persistence.schema-generation.database.action
javax.persistence.sql-load-script-source jakarta.persistence.sql-load-script-source

Many Hibernate-native keys such as hibernate.show_sql, hibernate.format_sql, and hibernate.hbm2ddl.auto keep their names, but not all of them do. Many renames sit in the old hibernate.ejb.* group: hibernate.ejb.cfgfile became hibernate.cfg_xml_file, hibernate.ejb.persistenceUnitName became hibernate.persistenceUnitName, and the hibernate.ejb.event prefix became hibernate.event. Other settings were removed or renamed individually, such as hibernate.hql.bulk_id_strategy, which became hibernate.query.mutation_strategy. The Hibernate 6.0 migration guide has the complete table.

Step 5: Clear the Follow-On Errors

Once the imports and descriptor are updated, the remaining failures usually fall into four groups.

Class Is Listed in persistence.xml but Not Annotated

This exact sentence, Class "..." is listed in the persistence.xml file, but is not annotated, usually comes from the Eclipse or Spring Tool Suite JPA validator (Dali), not from Hibernate itself. The giveaway is that the application can still start and pass persistence tests. Confirm that with a clean test run; if it passes, update the IDE and, if the warning persists, ignore that specific validation rather than disabling all JPA validation.

If the application really does fail, check these causes in order:

  1. The entity still imports javax.persistence.Entity. Hibernate 6 sees no Jakarta @Entity, so the class is not part of the metamodel.
  2. The class name in persistence.xml is stale after a package rename, or the descriptor lists a class that is not compiled into the runtime classpath.
  3. Two persistence.xml files are present, for example one in src/main/resources and an old copy left in target/classes or src/test/resources.
  4. The descriptor names an old provider. A persistence.xml that declares org.eclipse.persistence.jpa.PersistenceProvider while EclipseLink 2.x is still on the classpath will not understand Jakarta annotations. Use EclipseLink 4.x or remove the explicit provider and let Boot use Hibernate.

The fix is to make the annotation and the provider agree, not to add a second @Entity or suppress the message globally.

Stale javax Imports and Mixed Namespaces

Run a targeted audit before assuming the migration is complete:

grep -RIn --include='*.java' -E 'javax\.(persistence|validation|servlet|transaction)' src/main src/test grep -RIn -E 'javax\.persistence|xmlns\.jcp\.org/xml/ns/persistence' src/main/resources 

A single entity left on javax.persistence is enough to break startup, because the provider builds its metamodel from Jakarta annotations. The same applies to a repository that imports javax.persistence.EntityManager or a configuration class that imports javax.persistence.EntityManagerFactory. Fix every persistence reference, then clean and rebuild so stale class files cannot mask the result.

If both APIs are on the classpath, compilation can succeed even when the runtime is wrong. That is why the dependency check in Step 1 matters: the compiler is happy to resolve an old jar that Hibernate 6 will never use.

Hibernate Settings That No Longer Apply

Beyond the JPA-standard property renames, Hibernate 6 removed several long-deprecated settings. A configuration that silently worked on Hibernate 5 can fail to boot or fall back to a different default. Search your properties and persistence.xml for hibernate.ejb. and for settings listed as removed in the migration guide. Pay particular attention to naming strategies, identifier generation, and multi-tenancy settings if you customized them, because their replacements are not always one-for-one string swaps.

Third-Party Libraries Still Compiled Against javax

Some dependencies are not part of the Boot BOM and may still be compiled against javax.persistence. Typical symptoms are NoClassDefFoundError: javax/persistence/Entity, ClassNotFoundException: javax.persistence.Persistence, or a NoSuchMethodError mentioning a javax.persistence type.

The right fix is to upgrade the library to a Jakarta-compatible release. OpenRewrite's Jakarta migration recipes cover JPA along with Servlet, Bean Validation, and other specifications, and the project notes that the recipes also update related third-party libraries such as Jackson, Jetty, EhCache, and EclipseLink to Jakarta-compatible versions. Run the recipe that matches your target, then review the diff rather than accepting it blindly.

If no Jakarta-compatible release exists, Eclipse Transformer can rewrite class files and JAR contents from javax to jakarta type names. It was built for exactly this problem and can process application dependencies before assembly. Treat it as a temporary bridge: it changes bytecode references, not the library's behavior or API design, and reflection or string-based configuration can still escape the rewrite. Schedule a real upgrade rather than keeping a transformed jar forever.

Step 6: Verify With a Persistence Test

A compiling project is not a migrated project. Add a test that boots the persistence unit and asserts one entity round-trips. Spring Boot's testing reference for @DataJpaTest notes that it scans @Entity classes, configures Spring Data JPA repositories, and uses an embedded database when one is available; it also provides a TestEntityManager for test-specific persistence operations.

package com.example.orders; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager; import static org.assertj.core.api.Assertions.assertThat; @DataJpaTest class OrderPersistenceTest { @Autowired private TestEntityManager entityManager; @Test void entityBootsAndRoundTrips() { Order saved = entityManager.persistFlushFind(new Order("A-100")); entityManager.clear(); Order found = entityManager.find(Order.class, saved.getId()); assertThat(found).isNotNull(); assertThat(found.getReference()).isEqualTo("A-100"); } } 

If you need the real database instead of the embedded replacement, add @AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE) and point the test at your normal datasource. For a full application-context check, add one smoke test that injects EntityManagerFactory and asserts it is open:

import jakarta.persistence.EntityManagerFactory; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import static org.assertj.core.api.Assertions.assertThat; @SpringBootTest class PersistenceStartupTest { @Autowired private EntityManagerFactory entityManagerFactory; @Test void persistenceUnitStarts() { assertThat(entityManagerFactory.isOpen()).isTrue(); } } 

Run the tests from a clean build:

./mvnw clean test ./gradlew clean test 

A clean build matters here. Incremental compilation can leave old .class files or generated sources that still reference javax.persistence, making a successful compile look like a successful migration when the runtime classpath is still mixed.

Conclusion

The javax.persistence cannot be resolved error after a Spring Boot 3 upgrade is a classpath and namespace problem, not an import typo. Confirm that the build resolves Boot 3 and Java 17, remove the old javax.persistence API and Hibernate 5 artifacts, and let spring-boot-starter-data-jpa bring in the Jakarta Persistence 3.1 API and Hibernate 6. Then rewrite persistence imports deliberately, update persistence.xml, orm.xml, and the javax.persistence.* property keys, and clean up stale generated sources.

The follow-on errors are easier to diagnose once you know what they mean. The "listed in persistence.xml but not annotated" message is often an IDE validator false positive, but it becomes a real mapping problem when an entity still uses javax.persistence.Entity or when an old provider is still configured. Third-party jars compiled against javax need Jakarta-compatible upgrades, with Eclipse Transformer reserved as a short-term bridge.

Finish by booting the persistence unit in a test and asserting a round-trip. That catches mixed namespaces, stale descriptors, and provider mismatches that a successful compile will happily hide.