Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

We've recently discovered production system was affected by http://opensource.atlassian.com/projects/hibernate/browse/HHH-3532 (Hibernate matches foreign keys on name, rather than signature and so will recreate them for you) and hibernate.hbm2ddl.auto=update is being removed from our next release.

I would be quite happy to just get rid of hibernate.hbm2ddl.auto altogether and manage our database ourselves. However, not all my colleagues share this world view and some are keen to add back in hibernate.hbm2ddl.auto=validate.

I'm concerned this will hit the same problem and I'm interested in finding more documentation about how this validation actually works. The Hibernate Community Documentation (http://docs.jboss.org/hibernate/core/3.3/reference/en/html/session-configuration.html) really just makes reference to the values.

Does anyone have any good documentation pointers, or any real life experience of using validate in a production system?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
375 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...