Search code examples
javahibernatejakarta-eehbm2ddl

How to force multiple hbm2ddl executions to run separatedly?


We deploy our JavaEE applications as WARs in multpile Wildfly-servers. As persistence-framework we use JPA with Hibernate as implementation.

To garantee a matching DB-Schema to our entity-classes we have the following entry in our persistence.xml:

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

This is now used for the ease of maintaining a highly volatile DB-schema up-to-date because our domain model is far from stable at the moment.

If we deploy, say 2, WARs (containing the same entities) in a single server instance, both WARs will try to update the DB-schema. We deploy via an Ansible copy task and this results in parallel startup from both WARs and parallel execution of both hbm2ddl executions which gives us errors.

The question is now, is there an Hibernate built-in way to prohibit parallel execution of schema migrations via hbm2ddl?


Solution

  • No. You should consider using a tool like Flyway or Liquibase to migrated your database.