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的更多相关文章

  1. HibernateUtil.java

    package com.hkwy.util; import org.hibernate.Session; import org.hibernate.SessionFactory; import org ...

  2. hibernate工具类HibernateUtil详解

    1.为什么要用hibernateUtil这个类,先看这段代码:     //加载配置文件信息默认为hiberna.cfg.xml,如果不是的话那么就在config()方法里面去解析他      Con ...

  3. 【SSH三大框架】Hibernate基础第二篇:编写HibernateUtil工具类优化性能

    相对于上一篇中的代码编写HibernateUtil类以提高程序的执行速度 首先,仍然要写一个javabean(User.java): package cn.itcast.hibernate.domai ...

  4. 一个简单的Hibernate工具类HibernateUtil

    HibernateUtil package com.wj.app.util; import org.hibernate.Session; import org.hibernate.SessionFac ...

  5. Hibernate之工具类HibernateUtil

    原创文章,转载请注明:Hibernate之工具类HibernateUtil  By Lucio.Yang 1.最简单的工具类,实现SessionFactory的单例共享,session的管理 pack ...

  6. HibernateUtil工具类的使用

    为了简化代码的重复性,使用HibernateUtil工具类对Hibernate有关的代码进行整合 主要实现有,getSessionFactory(),getSession(),closeSession ...

  7. HibernateUtil hibernate4.0以上

    package com.test.bbs.util; import org.hibernate.Session; import org.hibernate.SessionFactory; import ...

  8. hibernateUtil类

    package com.test.Util; import org.hibernate.SessionFactory; import org.hibernate.cfg.AnnotationConfi ...

  9. hibernate课程 初探一对多映射2-3 创建hibernateUtil工具类

    本节主要内容:创建hibernateUtil工具类:demo demo: HibernateUtil.java package hibernate_001; import org.hibernate. ...

随机推荐

  1. ubuntu用apt安装apache2时,出现E:未发现软件包 apache2

    解决方法:使用sudo apt-get update更新软件包 更新软件包失败,多半使用因为源文件不干净,在/etc/apt下重新自己新写一份源文件 然后执行 sudo apt-get update

  2. 关于tesseract-ocr3的训练和使用

    众所周知,这是一个出色的字符识别软件.这个开源项目可以在http://code.google.com/p/tesseract-ocr/downloads/list下载. 在使用时,建议使用3而不要使用 ...

  3. tcp转发

    Proxy.java package com.dc.tcp.proxy; import java.io.IOException; import java.net.ServerSocket; impor ...

  4. CMFCPropertyGridProperty SetValue 出错处理

    对CMFCPropertyGridProperty SetValue时容易报错,这种情况一般是Property和value的类型不匹配造成的. 在创建property的时候,指定了数据类型,如果set ...

  5. 尝试一下代码高亮。。成功的话明天写一篇blog

    using System; using System.Collections; using UnityEngine; public class Time : MonoBehaviour { // Us ...

  6. Fiddler抓包之IOS

    Fiddler是一个http协议调试代理工具,它能够记录并检查所有你的电脑和互联网之间的http通讯,设置断点,查看所有的"进出"Fiddler的数据(指cookie,html,j ...

  7. ImageUtil(验证码数据生成工具类)

    登录界面时,常常会使用到验证码图片生成,程序如下: package util; import java.awt.Color; import java.awt.Font; import java.awt ...

  8. flash中字体兼容性

    非谷歌浏览器设置字体font时需设置为该字体的(英文名字)或者(中文名字+可读性消除锯齿), 谷歌浏览器设置字体font时需设置为该字体的(中文名字) 总结:静态文本一般通过选择可读性消除锯齿来能实现 ...

  9. 02 Apache Solr: 概览 Solr在信息系统架构中的位置

    概述:      Apache Solr是一个用JAVA语言构建在Apache Lucene项目上的开源的企业级搜索平台.主要特性包含:全文搜索.命中高亮.片段式搜索.实时索引.动态集群.数据库集成. ...

  10. oracle java SE

    http://www.oracle.com/technetwork/java/javase/downloads/index.html