ITeye博客

根据hibernate.cfg.xml文件生成POJO数据库表的工具类

zljava · 2008-12-24 23:35 · Hibernate · Markdown

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

评论(3)

  1. #3 楼 · 王添宝 · 2012-04-15 02:39

    我还以为是什么呢

  2. #2 楼 · ydsakyclguozi · 2009-05-21 11:11

    博主,很好很强大

  3. #1 楼 · zjb10000 · 2009-03-17 21:35

    感谢, :D

评论功能维护中,当前仅展示历史评论。