2.hql查询实体:工具类
2016-06-25 09:33
183 查看
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); } }
相关文章推荐
- 4.hql简单属性查询:测试
- 4.hql查询实体:测试
- 1.hql查询实体:Object,hbm
- 5.hql简单属性查询:总结
- 2.hql简单属性查询:工具类
- 3.hql简单属性查询:hibernate.cfg.xml
- MySQL中Union子句不支持order by的解决方法
- 1.hql简单属性查询:Object,hbm
- 编写一个jsp程序,实现用户登录,当用户输入的用户或密码错误时,将页面重定向到错误提示页,并在该页面显示30秒后 自动回到用户登录界面
- 安装get_homologues
- 秦谊:区块链目前还未达到大型商业应用阶段
- 如何成为资源整合高手
- iOS sqlite3数据库解析
- (Android)The connection to adb is down, and a severe error has occured.解决方法
- Codeforces Round #359 (Div. 2) A. Free Ice Cream 水题
- 生产者消费者模型(二)-引入ArrayBlockingQueue
- 《算法竞赛入门经典》学习笔记 2.4.4 C++中的输入输出
- 让客户自我成交的秘笈
- c++中位运算
- 生产者消费者模型你知道多少