2.一对多单向关联(班级对学生):工具类
2016-04-19 14:49
218 查看
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); } }
相关文章推荐
- MySQL触发器中通过SELECT语句给变量赋值
- foundation常用类笔记
- CG 知识摘要
- 【VIP】342. Power of Four 【E】【leetcode】
- Lua学习笔记
- fiddler使用
- 未能正确加载“Microsoft.VisualStudio.Editor.Implementation.EditorPackage”包
- 进程 线程 的区别
- MySQL学习笔记—插件式存储引擎
- poj1046 枚举
- MySQL压缩表
- java.lang.IllegalStateException:Cannot add header view to list==setAdapter has already been called.
- linux设备模型
- Ubuntu 文件文件夹查看权限和设置权限
- caffe 导读
- PHP中静态变量的使用
- Maven具体解释之------maven版本号管理
- sql server 判断是否存在数据库,表,列,视图
- webpack 入门教程
- 聚合命令