Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is there any liquibase issue with hibernate hbm2ddl create?

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.

like image 454
black sensei Avatar asked Aug 19 '10 18:08

black sensei


People also ask

What does hibernate hbm2ddl Auto Create This means *?

hibernate.hbm2ddl.auto. Automatically validates or exports schema DDL to the database when the SessionFactory is created. With create-drop , the database schema will be dropped when the SessionFactory is closed explicitly.

What is the default value for Hibernate hbm2ddl auto property?

hbm2ddl. auto defaults to Hibernate not doing anything. Show activity on this post. Automatically validates or exports schema DDL to the database when the SessionFactory is created.

How do I stop a table from hibernation?

Just set the hibernate. hbm2ddl. auto property to none instead of update since you don't need the DB schema to be generated for you.


1 Answers

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
like image 90
Nathan Voxland Avatar answered Nov 15 '22 00:11

Nathan Voxland