Hibernate根据实体生成数据库表

来源:互联网 发布:centos 6.5 php7 编辑:程序博客网 时间:2024/05/01 15:46

package org.xia.utils;

import org.hibernate.cfg.Configuration;
import org.hibernate.tool.hbm2ddl.SchemaExport;
/**
 * 根据hibernate.cfg.xml配置文件和相应实体类及其.hbm.xml文件生成对应的数据库表
 * 步骤:
 * 1.建立hibernate.cfg.xml配置文件且在数据库url后面指定数据库名称jdbc:mysql://localhost:3306/DB_NAME(该配置文件放在src根目录)
 * 2.建立好相应的POJO类和对应的.hbm.xml文件(需要hibernate.cfg.xml中配置)
 * 3.创建数据库DB_NAME;
 * 4.打开数据库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);
 }
}

原创粉丝点击