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. ...
随机推荐
- maven的配置环境及Myeclipse部署Maven项目
1.官网下载maven>解压>配置环境变量:在path后面加上 D:\software\apache-maven-3.3.9\bin; 2.cmd/mvn -version 测试 显示版 ...
- 8086cpu-intel汇编指令简介
jcxz 有条件跳转指令,cx为跳转条件.如果(cx)==0则跳转到指定标号处.跳转地址在机器码中已相对位置(-128~127)给出. 相当于 if((cx)==0) ...
- ViewPager的简单使用
1.布局文件 a.主布局文件 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xml ...
- JS---如何避免用户在请求时“猛击”
var isAjax=false;//是否正在执行ajax请求,此处表示不在拿数据 var getInfoByTrainCode=function () { if(isAjax) return;//如 ...
- python第二十天-----Django补充
学习python已经20天了啊,从一个不萌萌哒的战5渣升级到了一个萌萌哒的战5渣 1.分页(这是一个很通用的模块,不论在任何框架里都可以使用哦) class Page(object): def __i ...
- HTML之电话: 邮箱: 网址
<p> 电话: <a href="tel:电话">电话</a> </p> <p> 邮箱: <a href=&quo ...
- bootstrap 时间控件带(时分秒)选择器
1.控件下载地址:http://www.bootcss.com/p/bootstrap-datetimepicker/index.htm,参数设置说明也在这个链接下面: 2.具体参数说明(复制原链接) ...
- 关于JS获取来路url问题
Javascript 正常取来源网页的URL只要用: document.referrer 就可以了! 但,如果来源页是Javascript跳转过来的,上边的方法就拿不到了!所以用: opene ...
- 更新CocoaPods
终端输入 : sudo gem install -n /usr/local/bin cocoapods –pre 更新了CocoaPods后,在原来的工程中执行了pod install命令后,报这样的 ...
- nginx.conf详解
##定义nginx运行的用户各用户组user nginx nginx; ##nginx进程数,建议设置与cpu核心数一致worker_processes 1; #为每个进程分配CPU的工作内核 wor ...