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
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>
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?