JPA - No suitable driver found for JDBC (Windows 10, Payara 5)

885 views
Skip to first unread message

William Van Woensel

unread,
Apr 3, 2018, 11:47:20 AM4/3/18
to Payara Forum
(I've asked this question on Stack Overflow as well)

Believe me, I know this question has been asked many times and has gotten an answer many times, and these answers seemed to have worked for some users. I've spent many hours trying the various proposed solutions and, while they work on Linux (Ubuntu) and Windows 7 they seem to have no effect on Windows (Windows 10 Home with jdk1.8.0_161). The web application is using EclipseLink for persistence.


I've tried including the mysql-connector-java-5.1.46-bin.jar file in the WAR archive (WEB-INF/lib), copying it to the payara5/glassfish/lib folder, as well as the payara5/glassfish/domains/domain1/lib/ and payara5/glassfish/domains/domain1/lib/applibs folders. I also tried specifying the library when deploying the web application, i.e., putting mysql-connector-java-5.1.46-bin.jar as the value in the library field. I updated the CLASSPATH environment variable with the path to the JAR file. Every time, the server was restarted. None of these actions have any effect. As said, note that they did work on Linux Ubuntu and Windows 7. I've tried using EclipseLink 2.5.0, 2.5.2, 2.7.0 and 2.7.1, as well as mysql-connector-java-5.1.27-bin.jar
and mysql-connector-java-5.1.46-bin.jar,all with no effect.


See below for the well-known stack trace:


Local Exception Stack:

Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.7.0.v20170811-d680af5): org.eclipse.persistence.exceptions.DatabaseException

Internal Exception: java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/rom
Error Code: 0
    at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:331)
    at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:326)
    at org.eclipse.persistence.sessions.DefaultConnector.connect(DefaultConnector.java:138)
    at org.eclipse.persistence.sessions.DatasourceLogin.connectToDatasource(DatasourceLogin.java:170)
    at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.setOrDetectDatasource(DatabaseSessionImpl.java:228)
    at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:804)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:254)
    at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:757)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getAbstractSession(EntityManagerFactoryDelegate.java:216)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.createEntityManagerImpl(EntityManagerFactoryDelegate.java:324)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:348)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:311)

Interestingly, the error mentions Eclipse Persistence Services 2.7.0 regardless of the EclipseLink implementation that is included in the WAR file.


Any thoughts would be greatly appreciated.

Steve Millidge

unread,
Apr 3, 2018, 12:32:03 PM4/3/18
to Payara Forum
Have you tried pinging the datasource from the administration console before deploying the web application? Assuming you are creating the datasource in Payara Server before deploying your application.

payara5/glassfish/lib should work for a golbally defined datasource
WEB-INF/lib should work if you are defining the datasource in your web application web.xml or via annotations.


William Van Woensel

unread,
Apr 3, 2018, 12:40:13 PM4/3/18
to Payara Forum
I'm relying on EclipseLink - in the persistence.xml file, I indicate the database to be used (which is online and accessible) in the JDBC URL. This is a standard use case. As far as I know I'm not creating a global or local datasource, but perhaps EclipseLink does that behind the scenes (?) See below for the persistence.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
    <persistence-unit name="XXX">
        ...
        <properties>
            <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
            <property name="javax.persistence.jdbc.user" value="root" />
            <property name="javax.persistence.jdbc.password" value="XXX" />
            <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/XXX" />
            <property name="eclipselink.ddl-generation" value="create-tables" />
        </properties>
    </persistence-unit>
</persistence>


(I can verify that the URL, user and password are correct.)

Steve Millidge

unread,
Apr 3, 2018, 12:48:03 PM4/3/18
to Payara Forum
I would recommend using a datasource rather than the driver directly.

There is an example using MySQL here which uses the driver in WEB-INF/lib and defines the datasource in the web.xml.
https://github.com/payara/Payara-Examples/tree/master/Payara-Micro/jpa-datasource-example

William Van Woensel

unread,
Apr 3, 2018, 12:49:40 PM4/3/18
to Payara Forum
Thanks - will try that and let you know!

William Van Woensel

unread,
Apr 3, 2018, 7:01:07 PM4/3/18
to Payara Forum
Yes, that worked! A data source is likely the best way to go anyway but I wanted to avoid the complexity and use the simplest setup .. which clearly didn't work. It's still strange to me that the original setup didn't work ..

Thanks a bunch. I posted the solution here.

Fabien Marsaud

unread,
Apr 27, 2018, 7:16:31 PM4/27/18
to Payara Forum
@William I ran into the same issue as you whilst demonstrating JDBC4+ features to someone in the most simple way..
Connector/J, the MySQL driver was embedded in the war through my pom.xml

This smells very much like a bug in Payara5 to have to actually register the Driver prior to using JDBC.
DriverManager.registerDriver(new com.mysql.cj.jdbc.Driver());

Maybe it has to do with the way Glassfish/Payara handles classloading ?

After that, I tried the same application with Wildfly and the driver registration is automatic - as it should be.
Reply all
Reply to author
Forward
0 new messages