更新3: addes下面的代碼給pom所以openjpa可以找到persistence.xml文件。有一些查詢錯誤,但我終於得到了openjpa工作:)。Openjpa maven插件錯誤
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
</resources>
UPDATE2:設置Maven插件在我的POM OpenJPA的。在運行我的mavan版本時,現在有一個很好的新錯誤。我的源文件夾中有一個名爲META-INF的文件夾,其中包含persistence.xml和openjpa.xml。
[ERROR] Failed to execute goal org.codehaus.mojo:openjpa-maven-plugin:1.1:enhance (enhancer) on project scarletreports: Execution enhancer of goal org.codehaus.mojo:openjpa-maven-plugin:1.1:enhance failed: MetaDataFactory could not be configured (conf.newMetaDataFactoryInstance() returned null). This might mean that no configuration properties were found. Ensure that you have a META-INF/persistence.xml file, that it is available in your classpath, or that the properties file you are using for configuration is available. If you are using Ant, please see the <properties> or <propertiesFile> attributes of the task's nested <config> element. This can also occur if your OpenJPA distribution jars are corrupt, or if your security policy is overly strict. -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:openjpa-maven-plugin:1.1:enhance (enhancer) on project scarletreports: Execution enhancer of goal org.codehaus.mojo:openjpa-maven-plugin:1.1:enhance failed: MetaDataFactory could not be configured (conf.newMetaDataFactoryInstance() returned null). This might mean that no configuration properties were found. Ensure that you have a META-INF/persistence.xml file, that it is available in your classpath, or that the properties file you are using for configuration is available. If you are using Ant, please see the <properties> or <propertiesFile> attributes of the task's nested <config> element. This can also occur if your OpenJPA distribution jars are corrupt, or if your security policy is overly strict.
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:593)
POM:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>openjpa-maven-plugin</artifactId>
<version>1.1</version>
<configuration>
<includes>**/jpa/**/*.class</includes>
<addDefaultConstructor>true</addDefaultConstructor>
<enforcePropertyRestrictions>true</enforcePropertyRestrictions>
</configuration>
<executions>
<execution>
<id>enhancer</id>
<phase>process-classes</phase>
<goals>
<goal>enhance</goal>
</goals>
</execution>
</executions>
</plugin>
更新:看來,persistence.xml中不包括在戰爭文件。仍然從eclipse運行本地測試也不起作用。在戰爭中手動放置persitence.xml會導致下一個錯誤。我的猜測是我錯過了我的一些目標。我只在我的pom中與openjpa有關。
<!-- include open jpa for connection with rational databases -->
<dependency>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa-all</artifactId>
<version>2.0.1</version>
</dependency>
老問題:
我在我的web應用程序中使用OpenJPA的一個問題。我收到以下錯誤。
<openjpa-2.0.1-r422266:989424 fatal user error> org.apache.openjpa.persistence.ArgumentException: A JDBC Driver or DataSource class name must be specified in the ConnectionDriverName property.
org.apache.openjpa.jdbc.schema.DataSourceFactory.newDataSource(DataSourceFactory.java:76)
我想不通爲什麼,因爲該屬性在配置定義和驅動程序包含與Maven(並部署有我的戰爭文件),我得到這個消息。 這是我的openjpa連接代碼。
public class UserManagerFactory {
private EntityManagerFactory emf;
private EntityManager em;
public void initEM() {
emf = Persistence.createEntityManagerFactory("localDB");
em = emf.createEntityManager();
}
public User getUser() {
initEM();
List<User> results = em.createQuery("select u from users as u", User.class).getResultList();
closeEM();
return results.get(0);
}
public void closeEM() {
em.close();
emf.close();
}
}
,這是我的persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="localDB" transaction-type="RESOURCE_LOCAL">
<class>package.User</class>
<properties>
<!-- enable warnings for debugging -->
<property name="openjpa.Log" value="DefaultLevel=WARN, Runtime=INFO, Tool=INFO, SQL=TRACE"/>
<!-- connection properties -->
<property name="openjpa.ConnectionURL" value="jdbc:mysql://localhost/test"/>
<property name="openjpa.ConnectionDriverName" value="com.mysql.jdbc.Driver"/>
<property name="openjpa.ConnectionUserName" value="root"/>
<property name="openjpa.ConnectionPassword" value=""/>
</properties>
</persistence-unit>
</persistence>
在TRACE級別激活日誌記錄以查看是否獲得更多有用的信息: ' –
2010-09-10 16:17:19