Table of Contents
Hibernate Integration (Since 1.6)
The LiquiBase-Hibernate is a replacement to Hibernate's ”hbm2ddl” functionality.
Advantages of LiquiBase over hbm2ddl
While hbm2ddl works in general, it is basically a database diff tool and therefore has all the problems associated with database diff tools.
The LiquiBase-Hibernate integration records the database changes required by your current Hibernate mapping to a change log file which you can then inspect and modify as needed before executing.
Development Process
Using Hibernate with LiquiBase consists of the following steps:
- Make needed changes to your Hibernate-mapped objects
- Run diffChangeLog between your Hibernate config file and your development database (see examples below)
- Inspect and modify new change sets (if needed)
- Update your database with the new changes
Example
Command Line
liquibase \
--driver=oracle.jdbc.OracleDriver \
--classpath=jdbcdriver.jar:hibernate.jar \
--url=jdbc:oracle:thin:@localhost:1521:oracle \
--username=scott \
--password=tiger \
--changeLogFile=path/to/changelog \
diffChangeLog \
--baseUrl=hibernate:YOUR_HIBERNATE.CFG.XML \
Ant
<target name="hibernate-update" depends="prepare"> <taskdef resource="liquibasetasks.properties"> <classpath refid="classpath"/> </taskdef> <diffDatabaseToChangeLog driver="${database.driver}" url="${database.url}" username="${database.username}" password="${database.password}" baseUrl="hibernate:YOUR_HIBERNATE.CFG.XML" outputFile="path/to/changelog.xml" classpathref="classpath" > </diffDatabaseToChangeLog> </target>
