Hibernate/JPA DB Schema Generation Best Practices

  1. It’s always recommended to generate the schema manually, preferably by a tool supporting database schema revisions, such as the great Liquibase. Generating the schema from the entities is great in theory, but were fragile in practice and causes lots of problems in the long run(trust me on this).

  2. In productions it’s always best to have manually generated and review the schema.

  3. You make an update to an entity and create a matching update script(revision) to update your database schema to reflect the entity change. You can create a custom solution(I’ve written a few) or use something more popular like liquibase(it even supports schema changes rollbacks). If you’re using a build tool such as maven or ant – it’s recommend to plug the db schema update util into the build process so that fresh builds stay in sync with the schema.

Leave a Comment