【问题标题】:OpenJPA - ArgumentException: JDBC driver or data source class nameOpenJPA - ArgumentException:JDBC 驱动程序或数据源类名称
【发布时间】:2014-07-12 23:29:22
【问题描述】:

我正在使用 maven 创建一个 OpenJPA 应用程序。 应用程序启动,但如果我尝试访问数据库实体,则会收到以下异常:

HTTP Status 500 - <openjpa-2.2.2-r422266:1468616 fatal user error> org.apache.openjpa.persistence.ArgumentException: The persistence provider is attempting to use properties in the persistence.xml file to resolve the data source. A Java Database onnectivity (JDBC) driver or data source class name must be specified in the openjpa.ConnectionDriverName or javax.persistence.jdbc.driver property. The following properties are available in the configuration: "org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl@442ce698".

persistence.xml 位于 META-INF 中,由 Netbeans 8 控制。 ConnectionDriverName 设置如下:

<property name="openjpa.ConnectionDriverName" value="org.apache.commons.dbcp.BasicDataSource"/>

我的 src\main\java\META-INF\persistence.xml(类标签减少,数据库设置改变):

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence">
  <persistence-unit name="PersistenceUnit" transaction-type="RESOURCE_LOCAL">
    <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
    <class>com.example.test.my.entities.User</class>
    <exclude-unlisted-classes>true</exclude-unlisted-classes>
    <properties>
      <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema"/>
      <property name="openjpa.Log" value="DefaultLevel=INFO, Tool=INFO, SQL=TRACE"/>
      <property name="openjpa.jdbc.DBDictionary" value="org.apache.openjpa.jdbc.sql.MySQLDictionary"/>
      <property name="openjpa.ConnectionDriverName" value="org.apache.commons.dbcp.BasicDataSource"/>
      <property name="openjpa.ConnectionFactoryProperties" value="PrettyPrint=true, PrettyPrintLineLength=80, PrintParameters=true"/>
      <property name="openjpa.ConnectionProperties" value="DriverClassName=com.mysql.jdbc.Driver,
             Url=jdbc:mysql://localhost:3306/database?autoReconnect=true,
             Username=usr,
             Password=pwd,
             MaxWait=60000,
             TestOnBorrow=true,
             validationQuery=select 1"/>
    </properties>
  </persistence-unit>
</persistence>

我使用的是 Tomcat 8(Tomcat 7 或 Tomee 的结果相同)。

【问题讨论】:

  • 编辑问题并添加persistence.xml文件。
  • 完成。 :) 提前感谢
  • 发布完整的堆栈跟踪。

标签: java tomcat netbeans openjpa


【解决方案1】:

通过切换到 eclipse 解决了这个问题,因为 netbeans 似乎对 persistence.xml 有一些问题。 在 Eclipse 中,我不得不使用以下 m2e-connector: https://github.com/hwellmann/m2eclipse-extras/raw/master/p2/(eclipse 软件仓库地址)

【讨论】:

    猜你喜欢
    • 2011-09-21
    • 2013-04-24
    • 1970-01-01
    • 2021-05-17
    • 1970-01-01
    • 2014-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多