简体   繁体   中英

No Persistence provider for EntityManager named (New)

I am attempting to call persistence.xml to display some data from a database in the Netbeans IDE. I have looked and tried the different methods that previous users have proposed but I am still unable to solve the problem.

I have used this to call the persistence unit,

EntityManagerFactory emf = Persistence.createEntityManagerFactory("TimeEven DataBasePU");

This is what is returned when I try to run the file,

Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named TimeEven DataBasePU
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:85)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
at internal.assesment.TimeTableEventList.main(TimeTableEventList.java:110)
C:\Users\User\Documents\NetBeansProjects\Timetable\nbproject\build-impl.xml:1051: The following error occurred while executing this line:
C:\Users\User\Documents\NetBeansProjects\Timetable\nbproject\build-impl.xml:805: Java returned: 1

This is the line 805 which is where the error seems to stem from

<java classname="@{classname}" dir="${work.dir}" failonerror="${java.failonerror}" fork="true">

As said previously,

I have already added the provider under the Persistence unit name,

<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>

And I have made sure that the Persistence is unit is in the META-INF folder,

C:\Users\User\Documents\NetBeansProjects\Timetable\src\META-INF\persistence.xml

It is in the Class Path, so I am not sure where the error lies.

Edit 1. Yep, I copied and pasted from the xml code (I misspelled it in there too haha)

Image of Persistence

Edit 2.

Image of Files and Libraries

Edit 3.

Source Directory

I think the exception you posted is caused when there is no persistence unit which matches to name you passed on Persistence.createEntityManagerFactory. In your case:

<persistence-unit name="TimeEven DataBasePU">

So, could you check your persistence.xml if you are sure that persistence unit's name is same as you wrote in the code?

Or, Posting your persistence.xml might be helpful to solve your problem.

EDIT 1: Can you check your dependencies?

If you use maven(pom.xml), It must have:

<dependency>
  <groupId>org.eclipse.persistence</groupId>
  <artifactId>javax.persistence</artifactId>
  <version>2.1.1</version>
  <scope>provided</scope>
</dependency>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM