Home
>
Java > Generating sql database schema with maven2 for hibernate3
Generating sql database schema with maven2 for hibernate3
I’m using maven with hibernate3 plugin to generate the sql code for my database schema/tables. I do so with the following configuration.
Also make sure you declare your driver in the plugin dependencies to be sure the driver can be loaded in the plugin. Otherwise you might get some JDBC exceptions.
Command line example:
mvn clean compile hibernate3:hbm2ddl |
Command line example:
mvn clean compile hibernate3:hbm2ddl
<!--
Hibernate 3 Plugin, used for schema creation
Usage example: mvn clean compile hibernate3:hbm2ddl
-->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
<version>2.0-alpha-2</version>
<configuration>
<components>
<component>
<name>hbm2ddl</name>
<implementation>annotationconfiguration</implementation>
</component>
</components>
<componentProperties>
<!-- Create Drop Statements -->
<drop>false</drop>
<!-- Enable Annotations -->
<jdk5>true</jdk5>
<!-- Define Database Properties to Use -->
<propertyfile>target/classes/database.properties</propertyfile>
<!-- Pretty Format SQL Code -->
<format>true</format>
<!-- Create tables automatically? -->
<export>false</export>
<!-- Output filename -->
<outputfilename>schema.sql</outputfilename>
</componentProperties>
</configuration>
<dependencies>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc14</artifactId>
<version>${oracle-driver.version}</version>
</dependency>
</dependencies> |
<!--
Hibernate 3 Plugin, used for schema creation
Usage example: mvn clean compile hibernate3:hbm2ddl
-->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
<version>2.0-alpha-2</version>
<configuration>
<components>
<component>
<name>hbm2ddl</name>
<implementation>annotationconfiguration</implementation>
</component>
</components>
<componentProperties>
<!-- Create Drop Statements -->
<drop>false</drop>
<!-- Enable Annotations -->
<jdk5>true</jdk5>
<!-- Define Database Properties to Use -->
<propertyfile>target/classes/database.properties</propertyfile>
<!-- Pretty Format SQL Code -->
<format>true</format>
<!-- Create tables automatically? -->
<export>false</export>
<!-- Output filename -->
<outputfilename>schema.sql</outputfilename>
</componentProperties>
</configuration>
<dependencies>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc14</artifactId>
<version>${oracle-driver.version}</version>
</dependency>
</dependencies>
HSQL’s in-process mode might help you.
I don’t see what HSQLDB has to do with generating the schema for an oracle database. Could you point it out to me?
thanks for that code! was very helpful!