---
title: "根据hibernate.cfg.xml文件生成POJO数据库表的工具类"
author: "zljava"
date: "2008-12-24T23:35:32Z"
tags: []
slug: "hibernate-cfg-xml-pojo"
draft: false
lastmod: "2008-12-24T23:37:15Z"
id: 301130
url: "https://zljava.iteye.com/blog/301130"
---

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);
	}
}