hibernate.cfg.xml 和每张表对应的hbm文件 生成数据库表
2013-01-21 21:38
288 查看
电脑重装系统忘记备份数据库了。 用项目里面的 hibernate.cfg.xml 和每张表对应的hbm文件 生成数据库表的代码:
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 HibernateSchemaExport { static Session session; static Configuration config = null; static Transaction tx = null; public static void main(String[] args) { try { config = new Configuration().configure(new File( "src/hibernate.cfg.xml")); System.out.println("Creating tables..."); SessionFactory sessionFactory = config.buildSessionFactory(); session = sessionFactory.openSession(); tx = session.beginTransaction(); SchemaExport schemaExport = new SchemaExport(config); schemaExport.create(true, true); System.out.println("Table created."); tx.commit(); } catch (HibernateException e) { e.printStackTrace(); try { tx.rollback(); } catch (HibernateException e1) { e1.printStackTrace(); } } finally { } } }
相关文章推荐
- hibernate.cfg.xml 和每张表对应的hbm文件 生成数据库表
- 根据hibernate.cfg.xml配置文件和相应实体类及其.hbm.xml文件生成对应的数据库表
- 在MyEclipse的web项目/java项目中,使用Hibernate-tools中的hbm2java和hbm2ddl工具,根据hbm文件自动生成pojo和数据库脚本
- 使用Hibernate-tools中的hbm2java和hbm2ddl根据hbm文件自动生成pojo和数据库脚本
- 通过Hibernate的hbm.xml文件生成数据库表
- Hibernate中利用配置文件(hbm)自动生成数据库表
- 将上传文件以二进制形式存入数据库中,并下载数据库中的二进制数据生成对应的文件
- netbeans 的通过数据库生成hbm映射文件与pojo实体类稍有问题
- 使用middlegen(由数据库表生成hbm文件)
- [原创]java WEB学习笔记81:Hibernate学习之路--- 对象关系映射文件(.hbm.xml):hibernate-mapping 节点,class节点,id节点(主键生成策略),property节点,在hibernate 中 java类型 与sql类型之间的对应关系,Java 时间和日期类型的映射,Java 大对象类型 的 映射 (了解),映射组成关系
- 将上传文件以二进制形式存入数据库中,并下载数据库中的二进制数据生成对应的文件
- maven项目配置自动生成数据库表对应 mapper 文件
- 使用Hibernate-tools中的hbm2java和hbm2ddl根据hbm文件自动生成pojo和数据库脚本
- 通过Hibernate的hbm.xml文件生成数据库表
- JPA学习笔记---JPA实体Bean的建立+配置文件+junit测试+自动生成(对应实体Bean的)数据库表+插入数据
- 在eclipse中使用MyBatis Geneator自动生成出对应数据库的实体与映射文件
- 使用Hibernate-tools中的hbm2java和hbm2ddl根据hbm文件自动生成pojo和数据库脚本
- 使用Hibernate-tools中的hbm2java和hbm2ddl根据hbm文件自动生成pojo和数据库脚本
- 使用Hibernate-tools中的hbm2java和hbm2ddl根据hbm文件自动生成pojo和数据库脚本
- 关于Hibernate不能自动生成数据库表-POJO和映射文件正确但是访问对应表出错-的原因