No Persistence provider for EntityManager named
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
No Persistence provider for EntityManager named ... means JPA could not find a configured persistence unit with that name, or it could not load a provider that knows how to create it. In plain terms, your code asked for an EntityManagerFactory, but the runtime could not match that request to a valid JPA configuration.
What JPA Is Looking For
When you call Persistence.createEntityManagerFactory("myUnit"), JPA searches for a META-INF/persistence.xml file on the classpath. Inside that file, it expects a persistence-unit element whose name matches the string you passed.
It also needs an actual provider implementation, such as Hibernate or EclipseLink, available at runtime. The JPA API alone is not enough.
A minimal example looks like this.
If myUnit is not defined correctly, the exception appears during factory creation.
The Most Common Causes
Persistence Unit Name Mismatch
This is the simplest cause. The name in Java must exactly match the one in persistence.xml.
If your code asks for myPersistenceUnit while the XML defines myUnit, JPA will fail.
persistence.xml in the Wrong Location
The file must end up at META-INF/persistence.xml on the runtime classpath. Putting it under the wrong source folder or packaging it incorrectly in the final artifact is a common problem.
In a standard Maven project, place it under src/main/resources/META-INF/persistence.xml.
Missing Provider Dependency
If the JPA API is present but Hibernate or another provider is missing, JPA has no implementation to boot.
For example, a Maven setup with Hibernate and H2 might look like this:
Mixing Framework Conventions
Spring Boot projects often rely on Spring Data JPA and auto-configuration rather than manual Persistence.createEntityManagerFactory(...) calls. If you copy plain JPA examples into a Spring Boot app without understanding the bootstrap model, configuration can become inconsistent.
A Working Minimal Configuration
With that file in the correct location and the provider jars installed, Persistence.createEntityManagerFactory("myUnit") should succeed.
A Practical Debugging Checklist
Use a strict checklist instead of guessing:
- confirm the exact persistence unit name used in code
- confirm
persistence.xmlis packaged underMETA-INF - confirm a provider dependency exists at runtime
- confirm the XML namespace and property names match your JPA generation
- check startup logs for classpath or provider-loading errors
The fourth point matters because older javax.persistence examples and newer jakarta.persistence examples are not interchangeable without considering dependency versions.
Common Pitfalls
The most common pitfall is thinking the JPA API dependency is the provider. It is only the interface layer. You still need Hibernate, EclipseLink, or another implementation.
Another common mistake is copying a persistence.xml file into the source tree but not into src/main/resources/META-INF, so it never reaches the runtime classpath.
Developers also get trapped by name mismatches that look harmless, such as MyUnit versus myUnit. JPA name matching is literal.
Summary
- JPA must find both a matching persistence-unit name and a provider implementation.
- Put
persistence.xmlatsrc/main/resources/META-INF/persistence.xml. - Make sure the unit name in Java exactly matches the XML configuration.
- Include a real provider such as Hibernate, not just the JPA API.
- Watch for
javax.persistenceversusjakarta.persistenceversion mismatches.
Related reading
- No serializer found for class org.hibernate.proxy.pojo.bytebuddy.ByteBuddyInterceptor
- No suitable driver found for jdbcmysql in Kafka Connect
- Node.js and postgres LISTEN
- node.js cannot find module 'mongodb
- No primary or default constructor found for interface java.util.List Rest API Spring boot
- No primary or default constructor found for interface org.springframework.data.domain.Pageable
- node.js never exits after insert to couchbase, opposite of most node questions
- node.js node-cassandra-client request failing

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.