Openjpa maven插件错误
更新3: 将以下代码添加到 pom 以便 openjpa 可以找到 persistence.xml 文件。留下了一些查询错误,但我终于让 openjpa 工作了:)。
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
</resources>
更新2:在我的pom.xml中为openjpa设置maven插件。现在在运行我的 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 未包含在 war 文件中。仍然从 eclipse 运行本地测试也不起作用。手动将 persistence.xml 放入 war 中会出现下一个错误。我的猜测是我错过了我的 pom 中的一些目标。我只在我的 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>
老问题:
我在网络应用程序中使用 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 中(并且它是与我的 war 文件一起部署的)。 这是我的 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>
Update 3:
Addes following code to the pom so openjpa could find the persistence.xml file. Got some query errors left but I finally got openjpa to work :).
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
</resources>
Update2: Set up maven plugin for openjpa in my pom. Got a nice new error now while running my mavan build. I do have a folder named META-INF in my source folder containing persistence.xml and 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>
Update: appears that persistence.xml isn't included in the war file. Still running a local test from eclipse isn't working either. Placing the persitence.xml manually in the war gives the next error. My guess is that i miss some goals in my pom. I only got this in my pom in relation to 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>
Old question:
I have a problem using openjpa in my web application. I get the following error.
<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)
I can't figure out why i get this message since the property is defined in the config and the driver is included with maven (and it is deployed with my war file).
This is my openjpa connection code.
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();
}
}
And this is my 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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这不是使用 Maven 时资源应该所在的位置,资源应该位于 src/main/resources 下,即如下所示:
如果遵循约定,则无需执行任何操作。如果不这样做,您将需要添加一些显式配置(包括测试配置)。我建议使用默认值。
That's not where resources are supposed to be when using Maven, resources are supposed to go under
src/main/resources
i.e. something like this:If you follow the convention, there is nothing to do. If you don't, you'll need to add some explicit configuration (including for tests). I suggest using the defaults.