No Persistence provider for EntityManager named X

You must move persistence.xml file to an appropriate location.

More specifically, add META-INF/persistence.xml file to the root of a source folder.

In this case, the following is an appropriate location: src\main\java\META-INF\persistence.xml

Here are the details:
(taken from the JPA spec)

A persistence.xml file defines a persistence unit. The persistence.xml
file is located in the META-INF directory of the root of the
persistence unit.

The root of the persistence unit is the key here.

If you are a non-Java EE app

The jar file or directory whose META-INF directory contains the
persistence.xml file is termed the root of the persistence unit.

If you are in a Java EE app, the following are valid

In Java EE environments, the root of a persistence unit must be one of
the following:

  • an EJB-JAR file
  • the WEB-INF/classes directory of a WAR file[80]
  • a jar file in the WEB-INF/lib directory of a WAR file
  • a jar file in the EAR library directory
  • an application client jar file

Leave a Comment

tech