2014-07-12 60 views
0

我使用maven創建OpenJPA應用程序。 應用程序啓動,但如果我嘗試訪問數據庫的實體,我得到以下異常:OpenJPA - ArgumentException:JDBC驅動程序或數據源類名稱

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: "[email protected]". 

persistence.xml中位於META-INF和受到控制的Netbeans的8 的ConnectionDriverName被設置爲以下幾點:

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

我的src \主\ 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的結果相同)。

+0

編輯問題並添加persistence.xml文件。 –

+0

完成。 :) 在此先感謝 – razon

+0

發佈完整的堆棧跟蹤。 – Rick

回答

相關問題