views:

107

answers:

1

Hello Gurus!

i'm having a light problem with liquibase and hibernate.I expect hibernate to create the schema when the hbm2ddl is set to create and then have liquibase polulate the database with an sql script file.
i've notice that when on validate it behaves as describe and on create it doesn't Especially on a testing environment when using hsqldb (in memory).I seem to be blind then.

is there a way to have my expected works with hsqldb as in populate the db after it creation by hibernate. thanks for reading this.

+1  A: 

Liquibase is best used as a replacement for hbm2ddl. That way you can have your data population occur when the database is in the state that fits that data, and later changesets can upgrade your inserted data along with other changes. If you run hbm2ddl first, then liquibase to populate the data, you will need to always be making changes to your insert data structure.

One way you can use hibernate and liquibase is to use the liquibase diff tool under ant or maven during development to append to your changelog file based on differences between your database and your hibernate model. Make sure you inspect what it is trying to do, since it isn't always what you expect (it decides to drop and add a column instead of renaming it). Once your changelog file has been created, you can run it like any changelog file by passing it to the liquibase spring bean on app startup, for example. You don't need to use both hbm2ddl and liquibase, as liquibase uses hbm2ddl to generate the hibernate "database" that liquibase compares your current database against.

With this, your steps are: 1. Make changes to your hibernate model 2. Run liquibase diff between hibernate and your existing database 3. Inspect your new liquibase changeSets 4. Execute your liquibase script against the database

The only issue may be that the hibernate diff tool may not be supported in maven like it is in ant and the command line, especially in 1.9.

If you don't want to deal with the liquibase diff tool, you can always append changeSets to the changelog file for each change manually. The XML format is designed to be easy to manually work with. In this case, your steps are:

  1. Make changes to your hibernate model
  2. Add required changeSet to your changelog file
  3. Execute your liquibase script against the database
  4. Test and repeat
Nathan Voxland
Thanks Nathan!!i get the drift now.This is what i'm doing right now.i removed hbm2ddl from sping context.then i included the schema change log to create the tables and then include the changelog that contains the insert statements (and csv files).works perfect.thanks guys really big thanks
black sensei