2

对于我当前的任务,我必须在 liferay 门户中部署我们的应用程序。部署本身是成功的,但是当应用程序启动时,会抛出“没有合适的驱动程序”异常。

环境:

  • Oracle 10g 速成版
  • 休眠 4 决赛
  • Liferay 6 与 Tomcat 7
  • OJDBC 6
  • c3p0 0.9
  • 使用 Maven 构建

我们应用程序的旧 .war 文件运行时没有任何异常。但是,环境中存在一些小的差异。

旧环境:

  • Oracle 10g 速成版
  • 休眠 3 决赛
  • Liferay 6 与 Tomcat 7
  • OJDBC 14
  • Hibernate 在连接池中构建
  • 不使用 maven 构建

我已经尝试过的事情:

  • 将 ojdbc.jar 从 webapp lib 文件夹移动到 liferay tomcat lib/ext 文件夹
  • 在 context.xml 中强制执行 Class Loader 的“webapp classes/libs/resources first”行为:
  • 删除c3p0再次使用ojdbc14(我认为它可能是由ojdbc6引起的)
  • 在旧版本中将 ojdbc14 与 ojdbc6 交换(有效)

新的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>

旧的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>

您是否知道如何解决问题或找到根本原因?

提前致谢。

编辑:

堆栈跟踪:

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

1 回答 1

5

经过三天的调试,我终于找到了解决方案:

在某些情况下,persistence.xml 中的给定驱动程序类被 hibernate/c3p0 忽略,因此 - 就像异常状态一样 - 找不到合适的驱动程序。为了防止这种情况,我在 c3p0-config.xml 中添加了以下行:

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

我希望它也可以帮助其他人:-)

于 2012-06-05T14:38:00.270 回答