2.hql条件查询:工具类
2016-03-31 14:10
253 查看
package com.bjpowernode.hibernate; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.cfg.Configuration; public class HibernateUtils { private static SessionFactory factory; static { try { //读取hibernate.cfg.xml文件 Configuration cfg = new Configuration().configure(); //建立SessionFactory factory = cfg.buildSessionFactory(); }catch(Exception e) { e.printStackTrace(); } } public static Session getSession() { return factory.openSession(); } public static void closeSession(Session session) { if (session != null) { if (session.isOpen()) { session.close(); } } } public static SessionFactory getSessionFactory() { return factory; } }
package com.bjpowernode.hibernate; import org.hibernate.cfg.Configuration; import org.hibernate.tool.hbm2ddl.SchemaExport; /** * 将hbm生成ddl * @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); } }
相关文章推荐
- 1.hql条件查询:Object,hbm
- 5.hql查询实体:总结
- IDEA中如何配置Tomcat和项目
- 关于JQuery中的Deferred延迟操作对象
- 免责声明
- 浅谈SOA
- Exception not a valid month
- session was killed
- console.log格式输出全解及console的其他方法
- Android studio 不能预览布局文件
- 4.hql条件查询:测试
- 3.hql条件查询:hibernate.cfg.xml
- Android屏幕适配全攻略(最权威的官方适配指导)
- MFC-创建互斥对象
- mysql存储过程详解(2)
- C# 字节转换成"B", "KB", "MB", "GB", "TB", "PB"实例
- struts2的入门程序
- 函数式非凡的抽象能力
- Composer中国全量镜像
- log4j.properties详解与例子