Problems with LiquiBase Maven integration and empty database (hibernate)

Hi,

I’ve started to use LiquiBase in a project integrated with Maven. I’ve configured LiquiBase Maven plugin as explained in the website and it seems that it works.

However, I’m finding a problem. If someone adds a changeset and I’ve not created my database. When I do “mvn clean install” I get an error as tables related with changes don’t exist.

I guess that the problem is because I’m executing LiquiBase before the database is created, this is automatically done by hibernate, the specified phase is: process-resources

Anyway even if I move LiquiBase execution to a later phase, the database is going to be created properly but the changeset is not being able to be applied anyway. It should be somehow marked as already applied.

For example, you could think in a changeset that change a column name. If you execute this change:

  • Before database creation is not going to work: Column doesn't exist.
  • After database creation is not going to work either: Column is already with right name.

A possible solution would be to have a first changeset with all the tables and fields created by hibernate and then add the new changesets. This would mean that I couldn’t take advantage of some changes that are automatically done by Hibernate, like add a new column and things like that.

Did you find this problem before? Any other solution?

Thanks you very much,
  Rego

Rego,

you could bind execute process to another lificycle phase, i.e. validate, initialize, generate-sources, process-sources, generate-resources if maven 3.0

What maven version you using? What is pom.xml you using?

I’m using Maven 2 and Pom 4. You can check it here: http://navalplan.git.sourceforge.net/git/gitweb.cgi?p=navalplan/navalplan;a=blob;f=pom.xml;h=0919e304be6fff354164f1229388ee92f2e82275;hb=HEAD

Anyway even if I move it to another phase I’ll still have the same problem. That’s what I tried to explain in my first post:

Originally posted by: mrego
For example, you could think in a changeset that change a column name. If you execute this change:
  • Before database creation is not going to work: Column doesn't exist.
  • After database creation is not going to work either: Column is already with right name.

Why it fails in both cases? Because of hibernate is creating the database using hbm.xml files and then it already creates the table with the new column name. So the change to rename the column can’t be applied.

For the moment I just can think in the solution of make a first changeset which create the whole database and then add changeset for the changes done over the database. I was just wondering if there is any chance to avoid the first huge changeset creating all tables and columns.

Thanks,
  Rego

I’ve finally created a first changelog with all changesets needed to create the database, thanks to generateChangeLog tool (http://www.liquibase.org/manual/generating_changelogs).

Then I disabled Hibernate schema generation (hbm2dll) and now we’re just using schema validation.

I think that it’s a good solution, now I will try to integrate diffChangeLog (http://www.liquibase.org/manual/hibernate) in Maven in order to make easier changelog modifications when some new table or column is created.

You can see the commit adding all this stuff in the next link: http://navalplan.git.sourceforge.net/git/gitweb.cgi?p=navalplan/navalplan;a=commit;h=fe9ed34c6ccde7109e5e3d56e48d63b2025c958d

Bye,
  Rego

Yes, you cannot use both hbm2ddl and liquibase since both are trying to do the same thing and will conflict.  Glad you found the solution, sorry it was so far down in my answer queue.

Nathan