Hibernate - hibernate.hbm2ddl.auto = validate

前端 未结 1 1509
后悔当初
后悔当初 2020-12-15 21:28

I am interested in how hibernate.hbm2ddl.auto=validate actually works and I am struggling to find comprehensive documentation.

We\'ve recently discovered production

相关标签:
1条回答
  • 2020-12-15 21:39

    I'm concerned this will hit the same problem and I'm interested in finding more documentation about how this validation actually works.

    In my opinion, the best documentation is the source code that you could check to see what is happening exactly. The relevant method is org.hibernate.tool.hbm2ddl.SchemaValidator#validate().

    I went quickly through the code and I don't think that the SchemaValidator verifies foreign keys in the database: it checks the presence of tables, columns, id generators but not foreign keys. A test against a pet database seems to confirm this behavior: dropping a FK constraint doesn't break schema validation (in other words, the validator checks if the application can run, not for referential integrity).

    Now, HHH-3532 being marked as fixed, why don't you upgrade to a newer version of Hibernate or, if changing the version of Hibernate is too heavy, why don't you apply the patch for HHH-3532 yourself?

    Having that all said, I don't use hibernate.hbm2ddl.auto=update to update production databases, I use change scripts. But I use hibernate.hbm2ddl.auto=validate and I'm happy with it.

    0 讨论(0)
提交回复
热议问题