I'm using JPA via Hibernate...
In my persistence.xml I configure hibernate to update the schema as follow :
<property name="hibernate.hbm2ddl.auto" value="update"/>
Is it better to let JPA manage our databases or is it better to manage the databases ourselves (manually) ...
<property name="hibernate.hbm2ddl.auto" value="none"/>
The senior developers I know said to me that the second method is better ... because it is a habit the DBA do in all good entreprises .. but I want to have more explanation ... I want to know why the second method is better? why we should not let JPA manage the tables and the relations it self ...
It is not good for many reasons, especially in production environments.
Versioning - you may want to version your database, most people do manually by keeping track of db changes, it's good to prepare a revert script for every change. It's important on the version release to have a rollback plan in case things go bad.
Script execution failure - In a database full of data, an alter table which adds a non-null column will fail, simply because existing records do not have this column. So there are additional steps which are best handled manually.
Accidental changes. A developer from your team may accidentally commit wrongly configured entities and wreak havoc on your schema.
The best is to keep the value of hibernate.hbm2ddl.auto to validate
, this way entity mappings are validated against database structure, and if there's any mismatch, Hibernate will warn.