import org.hibernate.cfg.Configuration;
import org.hibernate.tool.hbm2ddl.SchemaExport;
执行操作之前要在数据库中建立好相应的数据库名称
/**
* DESC-根据hibernate.cfg.xml配置文件和相应实体类及其.hbm.xml文件生成对应的数据库表
* 使用步骤:
* 1.建立hibernate.cfg.xml配置文件且在数据库url后面指定数据库名称jdbc:mysql://localhost/DB_NAME(该配置文件放在src根目录)
* 2.建立好相应的POJO类和对应的.hbm.xml文件(需要hibernate.cfg.xml中配置)
* 3.创建数据库:create database DB_NAME;
* 4.打开数据库:use DB_NAME;
* 5.手动执行此类
* @author Administrator
*
*/
public class ExportDB {
public static void main(String[] args) {
//读取hibernate.cfg.xml文件
Configuration cfg = new Configuration().configure();
SchemaExport export = new SchemaExport(cfg);
export.create(true, true);
}
}
有hibernate实体类到数据库
最新推荐文章于 2018-03-09 17:39:31 发布
本文介绍如何使用Hibernate根据配置文件及实体类自动生成数据库表。主要包括配置hibernate.cfg.xml文件、创建实体类与映射文件、手动执行生成表的操作。
1万+

被折叠的 条评论
为什么被折叠?



