【问题标题】:maven openjpa sql generation issuemaven openjpa sql生成问题
【发布时间】:2012-10-21 21:42:56
【问题描述】:

我正在尝试将 sql 生成器目标添加到我的 openjpa 插件中。我使用 OpenJPA 2.2.0。我让 jpa 增强器使用 pom.sql 文件的以下相关部分:

<build>

    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.openjpa</groupId>
                <artifactId>openjpa-maven-plugin</artifactId>
                <version>${org.apache.openjpa.version}</version>
                <configuration>
                    <includes>org/someorg/models/local/*.class</includes>

                    <addDefaultConstructor>true</addDefaultConstructor>
                    <connectionDriverName>org.postgresql.Driver</connectionDriverName>
                    <enforcePropertyRestrictions>true</enforcePropertyRestrictions>
                    <sqlFile>src/main/resources/sql/create.sql</sqlFile>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>

    <plugins>

        <plugin>
            <groupId>org.apache.openjpa</groupId>
            <artifactId>openjpa-maven-plugin</artifactId>
            <version>${org.apache.openjpa.version}</version>

            <executions>
                <execution>
                    <id>enhancer</id>
                    <phase>process-classes</phase>
                    <goals>
                        <goal>enhance</goal>
                    </goals>
                </execution>                    
            </executions>
            <dependencies>
                <dependency>
                    <groupId>org.apache.openjpa</groupId>
                    <artifactId>openjpa</artifactId>
                    <!-- set the version to be the same as the level in your runtime -->
                    <version>${org.apache.openjpa.version}</version>
                </dependency>
            </dependencies>
        </plugin>
</plugins>

然后我尝试将以下内容添加到 openjpa 插件的执行部分:

<execution>
    <id>sql</id>
    <phase>generate-resources</phase>
    <goals>
        <goal>sql</goal>
    </goals>
</execution>

执行 mvn -e install 命令时出现以下错误: http://pastebin.com/TENgXezJ

在没有 -e 开关的情况下运行的较短版本:

[ERROR] 
Failed to execute goal org.apache.openjpa:openjpa-maven-plugin:2.2.0:sql(sql) on project batchpoc: 
Execution sql of goal org.apache.openjpa:openjpa-maven-plugin:2.2.0:sql 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]
[ERROR]

我错过了什么?

【问题讨论】:

  • 错误信息明确指出找不到persistence.xml。你把它放在META-INF了吗?
  • @maba 是的,它位于 src/main/resources/META-INF 中,它应该可以工作,因为我可以增强类或者增强与 persistence.xml 无关?

标签: java maven openjpa


【解决方案1】:

好的,所以我自己解决了。显然,诀窍不在 pom.xml 中,而是在 persistence.xml 中的持久性单元定义中

这真的很容易。我刚刚加了

<property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema"/>

我已经完成了。

显然对于 OpenJPA,您还需要根据此处的信息列出您希望生成的实体类: http://planet.jboss.org/post/generate_a_database_schema_with_openjpa_and_hibernate_on_jboss_as_7

因为我之前已经列出了我的课程,所以我不认为这是一个必要的步骤。

【讨论】:

    猜你喜欢
    • 2012-08-12
    • 2012-03-29
    • 1970-01-01
    • 2021-08-06
    • 2012-08-28
    • 1970-01-01
    • 2011-05-08
    • 1970-01-01
    • 2016-07-29
    相关资源
    最近更新 更多