Liferay: No suitable driver found

2019-07-15 11:27发布

问题:

For my current task I have to deploy our application in a liferay portal. The deployment itself was successful, but when the application is at start up a "No suitable driver" exception is thrown.

Environment:

  • Oracle 10g Express
  • Hibernate 4 Final
  • Liferay 6 with Tomcat 7
  • OJDBC 6
  • c3p0 0.9
  • Build with maven

An older .war file of our app runs without any exceptions. However, there are some small differences in the environment.

Old environment:

  • Oracle 10g Express
  • Hibernate 3 Final
  • Liferay 6 with Tomcat 7
  • OJDBC 14
  • Hibernate build in connection pool
  • Build without maven

Things I already tried:

  • Move the ojdbc.jar from the webapp lib folder to the liferay tomcat lib/ext folder
  • Enforce "webapp classes/libs/resources first" behaviour of Class Loader in context.xml:
  • Remove c3p0 to use ojdbc14 again (i thought it may be caused by ojdbc6)
  • Swap the ojdbc14 with ojdbc6 in the old build (it works)

New persistence.xml:

<persistence-unit name="ipointdefault">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<mapping-file>META-INF/hbm.xml</mapping-file>
<class>Entity declaration...</class>
<properties>
    <property name="javax.persistence.jdbc.driver" value="oracle.jdbc.driver.OracleDriver" />
    <property name="javax.persistence.jdbc.url" value="jdbc:oracle:thin:@HOST:PORT:DB" />
    <property name="javax.persistence.jdbc.user" value="user" />
    <property name="javax.persistence.jdbc.password" value="pw" />
    <property name="hibernate.hbm2ddl.auto" value="update" />

    <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />
    <property name="hibernate.archive.autodetection" value="class" />
    <property name="hibernate.current_session_context_class" value="thread" />
    <property name="hibernate.connection.pool_size" value="10" />
    <property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider" />
    <property name="hibernate.bytecode.use_reflection_optimizer" value="true" />
    <property name="hibernate.c3p0.acquire_increment" value="3" />
    <property name="hibernate.c3p0.min_size" value="3" />
    <property name="hibernate.c3p0.max_size" value="5" />
    <property name="hibernate.c3p0.timeout" value="10800" />
    <property name="hibernate.c3p0.idleConnectionTestPeriod" value="1800" />
    <property name="hibernate.c3p0.max_statements" value="0" />
</properties>

Old persistence.xml:

<persistence-unit name="ipointdefault">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>Entity declaration...</class>
<properties>
    <property name="javax.persistence.jdbc.driver" value="oracle.jdbc.driver.OracleDriver" />
    <property name="javax.persistence.jdbc.url" value="jdbc:oracle:thin:@HOST:PORT:DB" />
    <property name="javax.persistence.jdbc.user" value="user" />
    <property name="javax.persistence.jdbc.password" value="pw" />
    <property name="hibernate.default-access" value="property" />
    <property name="hibernate.hbm2ddl.auto" value="update" />
    <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />
    <property name="hibernate.archive.autodetection" value="class" />
    <property name="hibernate.current_session_context_class" value="thread" />
    <property name="hibernate.connection.pool_size" value="10" />
    <property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider" />
    <property name="hibernate.bytecode.use_reflection_optimizer" value="true" />
</properties>

Do you have any idea how to solve the problem or to find the root cause at all?

Thanks in advance.

Edit:

Stacktrace:

java.sql.SQLException: No suitable driver
    at java.sql.DriverManager.getDriver(DriverManager.java:264)
    at com.mchange.v2.c3p0.DriverManagerDataSource.driver(DriverManagerDataSource.java:224)
    at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:135)
    at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182)
    at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171)
    at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)
    at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)
    at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)
    at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)
    at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)

回答1:

After three days of debugging I finally found the solution:

Under certain circumstances the given driver class in the persistence.xml was ignored by hibernate/ c3p0 and because of this -like the exception states- no suitable driver could be found. To prevent this I added the following line to my c3p0-config.xml:

<property name="driverClass">oracle.jdbc.driver.OracleDriver</property>

I hope it helps others as well :-)