从 JPA 注释的实体类自动生成数据模式 [英] Auto generate data schema from JPA annotated entity classes

查看:30
本文介绍了从 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 来自休眠.文档是 这里.

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

这篇关于从 JPA 注释的实体类自动生成数据模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆