How to check that Hibernate mapping configuration matches database? I'd like know if I am using wrong version of hibernate mapping before I start executing update and queries, which then would fail.
I have bunch of classes that have been mapped with Hibernate annotations. I also have connection to corresponding database. Now I'd like to check if Hibernate mapping matches the database.
I'd like to check at least following things:
I'd prefer that I do not have to execute queries to mapped tables, preferably the check is based solely on database meta data.
Hibernate Validator allows to express and validate application constraints. The default metadata source are annotations, with the ability to override and extend through the use of XML. It is not tied to a specific application tier or programming model and is available for both server and client application programming.
Define Hibernate Mapping FileThe <class> elements are used to define specific mappings from a Java classes to the database tables. The Java class name is specified using the name attribute of the class element and the database table name is specified using the table attribute.
From Hibernate configuration docs:
hibernate.hbm2ddl.auto
Automatically validates or exports schema DDL to the database when the SessionFactory is created. With create-drop, the database schema will be dropped when the SessionFactory is closed explicitly.
e.g. validate | update | create | create-drop
So, you can set it to validate
and it will verify if everything in your hibernate mappings is present in the database. If you set it to update
, then every time you add a mapped class or property, the underlying db schema will be updated to reflect that change.
You also have a command-line tool - SchemaUpdate
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With