HibernateUtil
package com.ssh.util; import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.tool.hbm2ddl.SchemaExport; public class HibernateUtil {
private static final SessionFactory sessionFactory = buildSessionFactory(); private static SessionFactory buildSessionFactory() {
try { //Hibernate 4.x 时代
Configuration cfg = new Configuration();
cfg.configure(); // SchemaExport se = new SchemaExport(cfg);
// se.create(true, true); ServiceRegistry sr =
new StandardServiceRegistryBuilder()
.applySettings(cfg.getProperties())
.build(); SessionFactory factory = cfg.buildSessionFactory(sr); return factory;
// Create the SessionFactory from hibernate.cfg.xml
// return new Configuration().configure().buildSessionFactory();
}
catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
} public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}
HibernateUtil的更多相关文章
- HibernateUtil.java
package com.hkwy.util; import org.hibernate.Session; import org.hibernate.SessionFactory; import org ...
- hibernate工具类HibernateUtil详解
1.为什么要用hibernateUtil这个类,先看这段代码: //加载配置文件信息默认为hiberna.cfg.xml,如果不是的话那么就在config()方法里面去解析他 Con ...
- 【SSH三大框架】Hibernate基础第二篇:编写HibernateUtil工具类优化性能
相对于上一篇中的代码编写HibernateUtil类以提高程序的执行速度 首先,仍然要写一个javabean(User.java): package cn.itcast.hibernate.domai ...
- 一个简单的Hibernate工具类HibernateUtil
HibernateUtil package com.wj.app.util; import org.hibernate.Session; import org.hibernate.SessionFac ...
- Hibernate之工具类HibernateUtil
原创文章,转载请注明:Hibernate之工具类HibernateUtil By Lucio.Yang 1.最简单的工具类,实现SessionFactory的单例共享,session的管理 pack ...
- HibernateUtil工具类的使用
为了简化代码的重复性,使用HibernateUtil工具类对Hibernate有关的代码进行整合 主要实现有,getSessionFactory(),getSession(),closeSession ...
- HibernateUtil hibernate4.0以上
package com.test.bbs.util; import org.hibernate.Session; import org.hibernate.SessionFactory; import ...
- hibernateUtil类
package com.test.Util; import org.hibernate.SessionFactory; import org.hibernate.cfg.AnnotationConfi ...
- hibernate课程 初探一对多映射2-3 创建hibernateUtil工具类
本节主要内容:创建hibernateUtil工具类:demo demo: HibernateUtil.java package hibernate_001; import org.hibernate. ...
随机推荐
- Tcc学习笔记(一) 开篇
TCC,全称Tiny C Compiler(http://bellard.org/tcc/),是一个颇具特色的C编译器,你能把它当作一个C语言解释器来用,也可以嵌入你自己的应用程序作一个动态代码生成器 ...
- Linux基础-常用命令
常用的压缩命令 一.tar 1.压缩:tar zcvf [压缩包名].tar.gz [待压缩的文件名 ... ] 2.解压缩:tar zxvf [压缩包名].tar.gz -C [指定的解压目录] 3 ...
- cefsharp在xp上运行
今天遇到一个坑.也是自己英语不足的体现.在xp上运行cefsharp.wpf. 查询了各种资料.按照说明一步一步的操作,都没有解决xp上运行cefsharp.wpf. 而且在xp上调试都不知道错误在哪 ...
- L440 无线网卡:由于该设备有问题,Windows 已将其停止(代码 43)
最近重装了系统,本来用的好好的,结果重启之后突然无线网卡不能用了,设备管理器老是黄色叹号!无线网卡设备状态:由于该设备有问题,Windows 已将其停止. (代码 43). 无线网卡型号:2 ...
- mysql学习(4)-mysqldump备份和恢复数据
背景 最近在公司做数据迁移方面的工作,使用mysql数据库在测试环境模拟数据迁移,在迁移测试的过程中需要做数据备份和恢复 mysql数据备份和恢复比较简单,可以选择mysqldump工具,这里简单提一 ...
- javascript json转为 go struct 小工具代码
/** * Created by cdpmac on 15/10/20. */ var topname="Ap"; var jdata={ "item": { ...
- Spring ioc容器
一.ioc容器 ioc (inversion of control)即控制反转,把某一个接口选择实现类的控制权转移给Spring容器来管理.调用类对该实现类的依赖关系由ioc容器注入(DI),传统的 ...
- NC nc5.x报表设置合计行是否显示
首先要先继承UI类 /** * 设置合计行是否显示 */ public TotalsReportUI() { super(); getReportBase().getBodyPanel().setTo ...
- AngularJs自定义指令详解(8) - priority
priority 默认值为0. 当一个元素上声明两个指令,而且它们的priority一样,谁先被调用?这个需要分情况讲.下面先给个例子: <!DOCTYPE html> <html& ...
- H5学习系列之Communication API
1 .postMessage API 首先介绍一下什么是iframe? 百度百科里这样写道:IFRAME,HTML标签,作用是文档中的文档,或者浮动的框架(FRAME). 我的理解就是网页中的网页. ...