Liquibase + Hibernate: Easy and Solid Database Migration
Join the DZone community and get the full member experience.
Join For Freeas i pointed out earlier liquibase is a stable and nice migration tool for sql databases in the java land. the problem i had is that i couldn’t get it working with hibernate while using annotations.
now just for my personal memory here are the steps to get it working.
download liquibase 1.9.5 (couldn’t get it working with 2.0.0
) and put the following libs in the
liquibase/lib folder:
dom4j-1.6.1.jar
h2-1.2.137.jar #or your prefered jdbc database driver
hibernate-annotations-3.5.1-final.jar
hibernate-commons-annotations-3.2.0.final.jar
hibernate-core-3.5.1-final.jar
hibernate-jpa-2.0-api-1.0.0.final.jar
slf4j-api-1.6.0.jar
you will need to put the 4 hibernate jars into the classpath parameter, too. to do a diff and update the changelog file via the command line do the following:
liquibase --loglevel=fine \
--driver=org.h2.driver \
--classpath=$cp \
--url=jdbc:h2:~/.myapp/h2db \
--username=sa \
--password=tmp \
--changelogfile=src/main/resources/dbchangelog.xml \
diffchangelog \
--baseurl=hibernate:src/main/resources/hibernate.cfg.xml
this means you compare the ‘old’ database with the new hibernate config. if you have problems while set-up you can look directly into the source file .
btw: here is the pom snippet for the hibernate deps:
<dependency>
<groupid>org.hibernate</groupid>
<artifactid>hibernate-core</artifactid>
<version>3.5.1-final</version>
</dependency>
<dependency>
<groupid>org.hibernate</groupid>
<artifactid>hibernate-annotations</artifactid>
<version>3.5.1-final</version>
</dependency>
Opinions expressed by DZone contributors are their own.
Comments