EclipseLink – Configuration error. Class [com.mysql.jdbc.Driver] not found [javax.persistence.PersistenceException]

The EclipseLink – JPA API is persistence service that provided a standard way to communicate with the database. The major important issue needs to take care of while development of a project using a JPA, is a database driver that can help the JPA communicates with the suggested database.

  • This post will cover a proper way to avoid such that exception can be thrown when a Database Driver is not deducted from the classpath.
  • If you have created your database connection and ping it successfully as already made in the article EclipseLink – JPA installation, there are no promises for your project to work. And once you have executed your application you’ve got the exception:
Exception Description: Configuration error. Class [com.mysql.jdbc.Driver] not found.
Exception in thread "main" javax.persistence.PersistenceException: Exception [EclipseLink-4003] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.DatabaseException
Exception Description: Configuration error. Class [com.mysql.jdbc.Driver] not found.
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy
(EntityManagerSetupImpl.java:766)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getAbstractSession
(EntityManagerFactoryDelegate.java:204)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.
createEntityManagerImpl(EntityManagerFactoryDelegate.java:304)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl
(EntityManagerFactoryImpl.java:336)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager
(EntityManagerFactoryImpl.java:302)
at net.javabeat.eclipselink.JPAImpl.main(JPAImpl.java:9)
Caused by: Exception [EclipseLink-4003] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5):
org.eclipse.persistence.exceptions.DatabaseException
Exception Description: Configuration error. Class [com.mysql.jdbc.Driver] not found.
at org.eclipse.persistence.exceptions.DatabaseException.configurationErrorClassNotFound
(DatabaseException.java:89)
at org.eclipse.persistence.sessions.DefaultConnector.loadDriverClass(DefaultConnector.java:267)
at org.eclipse.persistence.sessions.DefaultConnector.connect(DefaultConnector.java:85)
at org.eclipse.persistence.sessions.DatasourceLogin.connectToDatasource(DatasourceLogin.java:162)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.setOrDetectDatasource
(DatabaseSessionImpl.java:204)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource
(DatabaseSessionImpl.java:741)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login
(EntityManagerFactoryProvider.java:239)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy
(EntityManagerSetupImpl.java:685)
... 5 more

The main cause of this exception is because the driver of the database is missed from your eclipse project’s classpath. It will not be added by default, you have to add it by yourself.

In case you are using a MySQL database, then you should add mysql-connector-java-5.1.24-bin.jar into your classpath.

To add the JAR follow the steps below:

  1. Right-Click on the eclipse project that uses the JPA.
  2. Select the properties from the menu.
  3. Make the Libraries tab activated.
  4.  Click on the Add External JAR
  5. Navigate into the location of the mysql-connector-java-5.1.24-bin.jar JAR file.
  6. Select it and click open.
  7. Click Okay.
  8. Try to execute the program once again, it should work properly.

Comments

comments

About Amr Mohammed

Speak Your Mind

*