How can I generate DDL from existing entities with annotations using a maven plugin?

后端 未结 2 1675
既然无缘
既然无缘 2021-01-15 12:56

I have maven project and I want to generate DDL from existing entities.

How can I do that?

Is there any maven plugin that I can generate the DDL?

I

相关标签:
2条回答
  • 2021-01-15 13:12

    openjpa-maven-plugin plugin provides a goal sql. Using this goal, it is possible to create the DDL from existing entities.

    <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>
    
    0 讨论(0)
  • 2021-01-15 13:26

    If you are using Hibernate as your JPA provider, check http://users.mafr.de/~matthias/articles/generating-ddl-scripts.html.

    Possible duplicate of generate DDL from JPA annotations, although the question there is phrased slightly differently?

    0 讨论(0)
提交回复
热议问题