从JPA注释实体类自动生成数据模式

从JPA注释实体类自动生成数据模式

问题描述:

我使用JPA(Hibernate的实现)注释实体类以持久化到关系数据库(MySQL或SQL Server)。有没有简单的方法从注释类自动生成数据库模式(表创建脚本)?

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?

我仍然在原型设计阶段,并预期频繁的模式更改。我想能够从带注释的代码中指定和更改数据模型。 Grails的类似之处在于它从域类生成数据库。

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.

可以使用 hbm2ddl 从Hibernate。文档此处

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