Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

No PersistenceProvider for EntityManager

 
Ashley Bye
Ranch Hand
Posts: 132
2
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:



And FlyingApp.java:



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?

Edit:

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