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
			<!-- 
				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>
  1. August 16th, 2008 at 01:29 | #1

    HSQL’s in-process mode might help you.

  2. Wytze
    August 16th, 2008 at 08:54 | #2

    I don’t see what HSQLDB has to do with generating the schema for an oracle database. Could you point it out to me?

  3. pawloch
    November 23rd, 2010 at 23:55 | #3

    thanks for that code! was very helpful!

  1. No trackbacks yet.

Time limit is exhausted. Please reload CAPTCHA.