Hibernate不同版本创建SessionFactory
来源:互联网 发布:收看日本电视台软件 编辑:程序博客网 时间:2024/06/05 06:36
在使用Hibernate过程中碰到不同版本的创建SessionFactory的方式有稍许不同,因为4.1版本和之前版本的文件结构组织有很大区别,而且有些方法稍微有改动。Hibernate4.1版本通过如下创建一个SessionFactory单例:package com.hibernate.util;import org.hibernate.cfg.Configuration;import org.hibernate.service.ServiceRegistry;import org.hibernate.service.ServiceRegistryBuilder;import org.hibernate.HibernateException;import org.hibernate.SessionFactory;public class HibernateUtil { private static final SessionFactory sessionFactory = buildSessionFactory(); private static SessionFactory buildSessionFactory() throws HibernateException { Configuration cfg = new Configuration(); cfg.configure(); ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(cfg.getProperties()).buildServiceRegistry(); SessionFactory sf = cfg.buildSessionFactory(serviceRegistry);; return sf; } public static SessionFactory getSessionFactory() { return sessionFactory; }}而在Hibernate3.3或之前的版本中,我们仅仅需要通过如下方式,SessionFactory sf = new AnnotationConfiguration().configure().buildSessionFactory();就可以创建SessionFactory,当然采用Annotation的情况下。当我们引入的包有相同的时候,Eclipse编译器会去找排在前边的jar包。Hibernate(4.3.8) StandardServiceRegistryBuilder Configuration configiguration = new Configuration().configure(); SessionFactory sessionFactory = configiguration .buildSessionFactory( new StandardServiceRegistryBuilder().applySettings(configiguration.getProperties()).build());
0 0
- Hibernate不同版本创建SessionFactory
- Hibernate不同版本创建SessionFactory
- hibernate不同版本获取sessionfactory的方式
- hibernate不同版本中sessionFactory获取方法
- hibernate创建sessionFactory的不同方式
- Hibernate创建SessionFactory根据Hibernate版本而异
- Hibernate 2.0--5.0.11各版本创建SessionFactory
- Hibernate 2.0--5.0.11各版本创建SessionFactory
- hibernate各版本创建sessionfactory(个人使用过)
- hibernate怎样创建SessionFactory
- Hibernate 4.3 创建 SessionFactory
- Hibernate实用类创建SessionFactory
- Hibernate 中 SessionFactory的创建
- Hibernate 4.3.5创建SessionFactory
- hibernate中SessionFactory的创建
- Hibernate创建sessionFactory工具类
- hibernate 创建 SessionFactory 的变化
- Hibernate SessionFactory 的创建方式
- poj 3126 Prime Path
- 在线数学函数图形和在线数据结构演示
- MFC消息种类
- Hibernate中 Hql语句中包含中文 无法查询到结果的解决办法
- VBS脚本教程:连续的创建文件
- Hibernate不同版本创建SessionFactory
- 杭电ACM-HDU1004-Let the Balloon Rise
- Android属性动画分析
- VHDL状态机
- PHP Twig模版的tags详解(中文)
- Java增强for循环 (java中的冒号)
- oracle读取char(2)字符型数据
- 纽约大学Yann LeCun深度学习
- 站在巨人的肩膀上,C++开源库大全