Thursday, March 12, 2009

Hibernate ddl (database schema) generation with help of Maven

pom.xml:
<plugin>
<!-- hibernate ddl generation -->
<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
<version>2.0-alpha-2</version>
<configuration>
<components>
<component>
<name>hbm2ddl</name>
<outputDirectory>.</outputDirectory>
</component>
</components>
<componentProperties>
<configurationfile>src/main/db/hibernate.cfg.xml</configurationfile>
<drop>false</drop>
<create>true</create>
<export>false</export>
<jdk5>true</jdk5>
<format>true</format>
</componentProperties>
</configuration>
<executions>
<execution>
<id>export-mysql</id>
<phase>process-classes</phase>
<goals>
<goal>hbm2ddl</goal>
</goals>
<configuration>
<componentProperties>
<propertyfile>src/main/db/hibernate-mysql.properties</propertyfile>
<outputfilename>target/mysql-ddl.sql</outputfilename>
</componentProperties>
</configuration>
</execution>
</executions>
</plugin>

hibernate.cfg.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!--Annotated classes-->
<mapping class="com.etymgiko.lyricscollection.model.Artist" />
<mapping class="com.etymgiko.lyricscollection.model.Song" />
</session-factory>
</hibernate-configuration>

hibernate-mysql.properties:
# This properties file defines the dialect for the MYSQL database
hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect

No comments:

Post a Comment

Followers