A simple Plugin for generating a Database-Schema from Hibernate 4 Mapping-Annotations
Hibernate comes with the buildin functionality, to automatically create or update the database schema. This functionality is configured in the session-configuraton via the parameter
hbm2ddl.auto (see Hibernate Reference Documentation – Chapter 3.4. Optional configuration properties). But doing so is not very wise, because you can easily corrupt or erase your production database, if this configuration parameter slips through to your production environment.
Alternatively, you can run the tools SchemaExport or SchemaUpdate by hand. But that is not very comfortable and being used to maven you will quickly long for a plugin, that does that job automatically for you, when you fire up your test cases.
In the good old times, there was the Maven Hibernate3 Plugin, that does this for you. But unfortunatly, this plugin is not compatible with Hibernate 4.x. Since there does not seem to be any successor for the Maven Hibernate3 Plugin and googeling does not help, I decided to write up this simple plugin (inspired by these two articles I found: Schema Export with Hibernate 4 and Maven and Schema generation with Hibernate 4, JPA and Maven).
I hope, the resulting simple to use buletproof hibernate4-maven-plugin is usefull!
Hi thx for updating the plugin to support hibernate 5. :)
Is there a way to generate “NOT NULL” constraints in the generated “output file” via existing @NotNull annotations (javax.validation.constraints.NotNull) like in the version before?
I don’t like to add @column(nullable = false) to every field.
Thx for your answer :)