hibernate 自动生成数据库(根据hibernate配置文件)
2011-03-24 20:00
666 查看
以前给学校学生会写了一个志愿者管理系统,用的是SSH框架。后来要维护的时候,发现数据库已经被我删掉了,而且也没有数据库的建表语句。幸好在学习Hibernate时记得有一个方法可以恢复数据库,前提是你要有hibernate的备置文件。嘻嘻 ……
好吧 话不多说 先讲一下怎么操作吧:
1.首先建立一下你的数据库。我的是mysql数据:create database vol;
2.在工程下建立一个类
package test;
/*
* 根据hibernate配置文件 自动生成数据库
* 前提 必须先建立一个空的数据库
* Edited By Chuanbo Wen
* email:nantian13@126.com
*/
import java.io.File;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.tool.hbm2ddl.SchemaExport;
public class CreateDB {
static Session session;
public static void main(String[] args) {
Configuration config = null;
Transaction tx = null;
config = new Configuration().configure();
System.out.println("Creating tables...");
SchemaExport schemaExport = new SchemaExport(config);
schemaExport.create(true, true);
System.out.println("Table created.");
}
}
好了 直接运行就可以了 有问题 情Email:nantian13@126.com
大家共通交流。
好吧 话不多说 先讲一下怎么操作吧:
1.首先建立一下你的数据库。我的是mysql数据:create database vol;
2.在工程下建立一个类
package test;
/*
* 根据hibernate配置文件 自动生成数据库
* 前提 必须先建立一个空的数据库
* Edited By Chuanbo Wen
* email:nantian13@126.com
*/
import java.io.File;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.tool.hbm2ddl.SchemaExport;
public class CreateDB {
static Session session;
public static void main(String[] args) {
Configuration config = null;
Transaction tx = null;
config = new Configuration().configure();
System.out.println("Creating tables...");
SchemaExport schemaExport = new SchemaExport(config);
schemaExport.create(true, true);
System.out.println("Table created.");
}
}
好了 直接运行就可以了 有问题 情Email:nantian13@126.com
大家共通交流。
相关文章推荐
- hibernate 根据配置文件自动生成数据库表
- hibernate根据配置文件生成数据库表
- 使用Hibernate-tools中的hbm2java和hbm2ddl根据hbm文件自动生成pojo和数据库脚本
- 用hibernate 的配置文件自动生成 数据库表
- 使用Hibernate-tools中的hbm2java和hbm2ddl根据hbm文件自动生成pojo和数据库脚本
- 如何根据hibernate的实体类和实体类配置文件生成数据库的表
- 如何根据hibernate的实体类和实体类配置文件生成数据库的表
- Mybaits根据数据库表自动生成entity,dao,mapper相关配置文件
- Hibernate 自动生成映射文件 || 根据pojo类生成数据库表
- 根据hibernate配置文件生成数据库建表脚本
- Hibernate中利用配置文件(hbm)自动生成数据库表
- 使用Hibernate-tools中的hbm2java和hbm2ddl根据hbm文件自动生成pojo和数据库脚本
- 使用Hibernate-tools中的hbm2java和hbm2ddl根据hbm文件自动生成pojo和数据库脚本
- 在MyEclipse的web项目/java项目中,使用Hibernate-tools中的hbm2java和hbm2ddl工具,根据hbm文件自动生成pojo和数据库脚本
- 使用Hibernate-tools中的hbm2java和hbm2ddl根据hbm文件自动生成pojo和数据库脚本
- 根据hibernate.cfg.xml配置文件和相应实体类及其.hbm.xml文件生成对应的数据库表
- Hibernate配置文件中hiberante.hbm2ddl.auto四个参数的配置----牛逼。可以自动生成数据库。
- hibernate根据配置文件生成数据库表
- 利用Hibernate配置文件反向生成数据库
- 关于Hibernate不能自动生成数据库表-POJO和映射文件正确但是访问对应表出错-的原因