Java – Auto generate data schema from JPA annotated entity classes

databasehibernatejakarta-eejavajpa

I'm using JPA (Hibernate's implementation) to annotate entity classes to persist to a relational database (MySQL or SQL Server). Is there an easy way to auto generate the database schema (table creation scripts) from the annotated classes?

I'm still in the prototyping phase and anticipate frequent schema changes. I would like to be able to specify and change the data model from the annotated code. Grails is similar in that it generates the database from the domain classes.

Best Solution

You can use hbm2ddl from Hibernate. The docs are here.

Related Question