Getting SQLException: Driver:org.hsqldb.jdbcDriver

2019-07-21 05:39发布

问题:

I am getting following exception in tomee deployed application.

 [EL Severe]: 2014-07-11 09:18:34.811--ServerSession(860687693)--Thread(Thread[http-bio-8081-exec-3,5,main])--Local Exception Stack: 
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: Driver:org.hsqldb.jdbcDriver@7078c2bb returned null for URL:"jdbc:mysql://localhost:3306/testDB"
Error Code: 0
    at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:316)
    at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:135)
    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)
    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:309)
    at org.apache.openejb.assembler.classic.ReloadableEntityManagerFactory.createEntityManager(ReloadableEntityManagerFactory.java:159)
    at org.apache.openejb.persistence.JtaEntityManagerRegistry.getEntityManager(JtaEntityManagerRegistry.java:115)
    at org.apache.openejb.persistence.JtaEntityManager.getEntityManager(JtaEntityManager.java:91)
    at org.apache.openejb.persistence.JtaEntityManager.find(JtaEntityManager.java:164)

heres my tomee.xml file,

<tomee>
  <Resource id="testDBPool" type="DataSource">
    jdbcDriverClassName = "com.mysql.jdbc.Driver"
    url = "jdbc:mysql://localhost:3306/testDB"
    username = "admin"
    password = "admin"
  </Resource>
</tomee>

I already put mysql_connector jar in my tomee/lib folder. My persistence.xml file as below,

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
    xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
    <persistence-unit name="TestPersistence"
        transaction-type="JTA">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <jta-data-source>jdbc/testDBPool</jta-data-source>
        <shared-cache-mode>NONE</shared-cache-mode>
        <properties>
            <property name="eclipselink.weaving" value="static" />
            <property name="eclipselink.logging.level.sql" value="FINEST" />
            <property name="eclipselink.logging.level" value="FINEST" />
            <property name="eclipselink.logging.level.cache" value="FINEST" />
        </properties>
    </persistence-unit>
</persistence>

I do not understand where I am wrong, why I am getting this exception? Please help me to solve this.

回答1:

The problem is that you are using the wrong property name to declare the JDBC driver. According to Apache TomEE: DataSource Configuration, the property for the driver name is jdbcDriver, and not jdbcDriverClassName. The default value for jdbcDriver is org.hsqldb.jdbcDriver. So as I commented earlier it will try to create a connection using HSQLDB, but with a MySQL JDBC url.

To fix your problem change your configuration to:

<tomee>
  <Resource id="testDBPool" type="DataSource">
    jdbcDriver = "com.mysql.jdbc.Driver"
    ...
  </Resource>
</tomee>