【问题标题】:How can I generate DDL from existing entities with annotations using a maven plugin?如何使用 Maven 插件从带有注释的现有实体生成 DDL?
【发布时间】:2012-08-30 11:38:36
【问题描述】:

我有 maven 项目,我想从现有实体生成 DDL。

我该怎么做?

是否有任何我可以生成 DDL 的 maven 插件?

我正在使用 JPA。(打开 jpa)

【问题讨论】:

  • 你说的是持久化实体吗?
  • @SkyDan 是的,JEE 持久性实体
  • 那么,我想maven与它无关。你的问题标题很混乱。
  • @skydan 我想在 Maven 中有一个可能性。因此很重要。例如使用适当的插件
  • 好吧,DDL 生成再次由持久化提供者实现。因此,请查看您的持久性提供程序的教程以获取信息。

标签: java jakarta-ee maven ejb jpa-2.0


【解决方案1】:

openjpa-maven-plugin 插件提供了一个目标sql。使用此目标,可以从现有实体创建 DDL。

<pluginManagement>
<plugin>
    <groupId>org.apache.openjpa</groupId>
    <artifactId>openjpa-maven-plugin</artifactId>
    <version>2.2.0</version>
    <configuration>
        <includes>**/entity/ *.class</includes>
        <addDefaultConstructor>true</addDefaultConstructor>
        <connectionDriverName>com.ibm.db2.jcc.DB2Driver</connectionDriverName>
        <enforcePropertyRestrictions>true</enforcePropertyRestrictions>
        <persistenceXmlFile>${basedir}/src/main/resources/META-INF/persistence.xml</persistenceXmlFile>
        <skip>${skip.jpa}</skip>
        <sqlFile>${basedir}/src/main/resources/database.sql</sqlFile>
    </configuration>
        <dependencies>
            <dependency>
                 <groupId>org.apache.openjpa</groupId>
                 <artifactId>openjpa</artifactId>
                 <version>2.1.1</version>
            </dependency>
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
                <version>1.6.6</version>
            </dependency>
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-simple</artifactId>
                <version>1.6.6</version>
            </dependency>
        </dependencies>
    </plugin>
</pluginManagement>

<plugin>
    <groupId>org.apache.openjpa</groupId>
    <artifactId>openjpa-maven-plugin</artifactId>
    <executions>
        <execution>
            <id>sql</id>
            <phase>generate-resources</phase>
            <goals>
                <goal>sql</goal>
            </goals>
        </execution>                    
    </executions>
</plugin>

【讨论】:

  • 非常有用!我花了几个小时才找到这篇文章,但是这个 maven 插件做得很好!
【解决方案2】:

如果您使用 Hibernate 作为您的 JPA 提供程序,请检查 http://users.mafr.de/~matthias/articles/generating-ddl-scripts.html

generate DDL from JPA annotations 的可能重复项,尽管问题的措辞略有不同?

【讨论】:

    猜你喜欢
    • 2011-07-23
    • 1970-01-01
    • 2013-02-04
    • 2012-04-09
    • 1970-01-01
    • 2016-01-03
    • 1970-01-01
    • 2022-07-29
    相关资源
    最近更新 更多