Win a copy of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications this week in the Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

No PersistenceProvider for EntityManager  RSS feed

Ashley Bye
Ranch Hand
Posts: 140
Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm having issues trying to connect to a MySQL DB using JPA with EclipseLink as the provider. Also, I am trying to learn both Maven and IntelliJ IDEA so am not yet familiar with their features or how they work fully, which may be half of the issue. Anyway, I am trying to test that everything is set up correctly by adding a record to a table in the database, but get the following error:


The database connection works fine since I generated my entities based on the database schema through running the JavaEE Persistence wizard on the main module. I then refactored the persistence unit name so it was no longer the default NewPersistenceUnit or whatever it was called. My persistence.xml:

I get an error on line 5 telling me that the class PersistenceProvider and the package jpa cannot be resolved. My project lib folder has the java.prsistence jar, but this does not contain the necessary class nor even the jpa sub-package.

It would seem that I have not done something correctly, or IntelliJ IDEA is not importing the correct library (I suspect the former to be more likely). I have tried to add a dependency to the Maven pom.xml, but can't work out how to do this through the IDE (the Cmd-N -> Generate Dependency option does not bring up any dependencies). Therefore, the pom.xml currently looks as follows:

Please can someone give me a shove in the right direction to sort this out?


I have manually added the dependencies for eclipse link and jpa, although I don't understand why IntelliJ didn't do this for me:

This has removed the error in persistence.xml. However, the error still remains when I try to run the program. My project structure is as below:

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!