Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Seam/Hibernate: liquibase before JPA startup

I have a Java EE web application (hibernate3, seam) that I'm using in Weblogic container. I want to introduce Liquibase for schema migrations. Currently we use

<property name="hibernate.hbm2ddl.auto" value="update"/>

which we want to drop because it can be dangerous.

I want the migration to automatically happen at deployments, so I'm using the servlet listener integration.

In web.xml, the first listener is:

<listener>
    <listener-class>liquibase.integration.servlet.LiquibaseServletListener</listener-class>
</listener>

Sadly, this listener comes into play after the Hibernate initialization and it throws missing table errors (because the schema is empty). I'm google-ing like a boss for hours and I'm a bit confused now.

Thanks in advance

UPDATE

If I set <property name="hibernate.hbm2ddl.auto" value="none" />, liquibase finishes it's job successfully and the app starts up as expected. If I set validate, it seems like hibernate schema validation takes place before liquibase and it cries because of missing tables.

UPDATE

It seems like Seam initializes Hibernate, but Liquibase listener is listed before SeamListener, so I have no clue on how to enable schema validation and liquibase at the same time...

like image 575
gyorgyabraham Avatar asked Nov 06 '13 13:11

gyorgyabraham


1 Answers

My understanding is that the LiquibaseServletListener requires the path to change log file which is passed using liquibase.changelog context param. So you already have a change log generated or am I missing something here ?

You can take a look at the liquibase hibernate integration library provided by Liquibase. This library works with both the classic hibernate configuration (via .cfg and .xml files) as well as JPA configuration via persistence.xml.

AFAIK, generating the changelog and running the change log are two seperate process. Liquibase hibernate integration library helps in generating the change log from the diff of current state of entities in persistence unit and the current database state.

like image 82
Shailendra Avatar answered Nov 02 '22 04:11

Shailendra