我正在使用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的结果相同)。
答案 0 :(得分:0)
通过切换到eclipse来解决它,因为看起来netbeans在persistence.xml上有一些问题。 在eclipse中我不得不使用以下m2e-connector: https://github.com/hwellmann/m2eclipse-extras/raw/master/p2/(eclipse软件存储库URL)