2

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)
Marius K.
  • 355
  • 2
  • 12
  • Did you try using c3p0 with OJDBC14? I believe you are correct in thinking it is some combination of the database/hibernate jars. Also, can you include a stack trace? – aglassman Jun 01 '12 at 14:41
  • The problem with OJDBC 14 is that it won't work with hibernate 4 (if i remind correct). – Marius K. Jun 01 '12 at 15:05
  • Did you check to insure Maven including the dependencies in the .war? (Sorry for the dumb questions, but you never know.) – aglassman Jun 01 '12 at 15:18
  • Yes, all dependencies are included in the .war file ;-) – Marius K. Jun 01 '12 at 15:31
  • I think I took a step closer to the solution: While remote debugging I saw, that the Oracle driver isn't load by anyone. However, I put it in the same directory as the Liferay default hsqldb driver. So I think that the hsqldb driver is loaded somewhere else... At this point my mood was very bad, but then I saw something interesting in the `Service$LazyIterator` class: You can put an configuration file into `META-INF/services` folder with services loaded at start-up. I created the file but my drivers won't get load. Perhaps I put the file at the wrong location. – Marius K. Jun 04 '12 at 09:50
  • Locations I tried: _tomcat/webapps/myapp/META-INF_, _myapp/WEB-INF/classes/META-INF_, _tomcat/work/Catalina/localhost/myapp/loader/META-INF_. – Marius K. Jun 04 '12 at 09:50
  • Regarding my last 2 comments: [where to put meta-inf services java sql driver in web app](http://stackoverflow.com/questions/10369695/where-to-put-meta-inf-services-java-sql-driver-in-web-app). And as stated in the answer, my ojdbc6.jar contains a file in the specified dir. – Marius K. Jun 04 '12 at 12:59

1 Answers1

5

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 :-)

Marius K.
  • 355
  • 2
  • 12