关于hibernate4.3版本之后org.hibernate.service.ServiceRegistryBuilder被弃用
之前一直都是使用hibernate4.2.21的我,有一天突然没有使用本地的jar包而是让IDEA自动下载最新版本的hibernate5.2.2之后,发现有几个经常使用的方法报错了.
-这真是让我惊了个呆,网上一搜,好像有这个问题的人还不少,然后发现果然是hibernate版本的问题——hibernate4.3之后已经没有了org.hibernate.service.ServiceRegistryBuilder这个类,它被弃用了这下子问题就迎刃而解了
-如果使用的是hibernate4.2之前的版本,那么方法就这么写:
//创建配置对象
Configuration config = new Configuration().configure();
//创建服务注册对象
ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(config.getProperties()).buildServiceRegistry();
//创建会话工厂对象
sessionFactory = config.buildSessionFactory(serviceRegistry);
//会话对象
session = sessionFactory.openSession();
//开启事务
transaction = session.beginTransaction();
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
-如果是hibernate4.3之后的版本,那么方法就这么写:
导入包更换:org.hibernate.boot.registry.StandardServiceRegistryBuilder;
//创建配置对象
Configuration config = new Configuration().configure();
//创建服务注册对象
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(config .getProperties()).build();
//创建会话工厂对象
sessionFactory = config.buildSessionFactory(serviceRegistry);
//会话对象
session = sessionFactory.openSession();
//开启事务
transaction = session.beginTransaction();
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
-甚至我还发现到hibernate5之后连上面的包都可以省略了:
//创建配置对象(读取配置文档)
Configuration config = new Configuration().configure();
//创建会话工厂对象
sessionFactory = config.buildSessionFactory();
//会话对象
session = sessionFactory.openSession();
//开启事务
transaction = session.beginTransaction();
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
至此问题圆满解决(撒花)
关于hibernate4.3版本之后org.hibernate.service.ServiceRegistryBuilder被弃用的更多相关文章
- Hibernate **关于hibernate4.3版本之后org.hibernate.service.ServiceRegistryBuilder被弃用**
之前一直都是使用hibernate4.2.21的我,有一天突然没有使用本地的jar包而是让IDEA自动下载最新版本的hibernate5.2.2之后,发现有几个经常使用的方法报错了. //创建配置对象 ...
- org.hibernate.service.ServiceRegistryBuilder被弃用
看视频教程是这样写的: //创建配置对象 Configuration config = new Configuration().configure(); //创建服务注册对象 ServiceRegis ...
- spring 集成 Hibernate4.3.X org.hibernate.service.jta.platform.spi.JtaPlatform异常
使用Spring3.2.4集成Hibernate4.3.5时,出现以下异常 Causedby:java.lang.ClassNotFoundException:org.hibernate.servic ...
- org.hibernate.service.classloading.spi.ClassLoadingException: Specified JDBC Driver com.mysql.jdbc.Driver class not found
今天在使用hibernate搭建开发环境的时候出现了一个不可思议的问题: org.hibernate.service.classloading.spi.ClassLoadingException: S ...
- hibernate4.0+版本和3.0+版本的区别总结
自己总结下hibernate4.1版本中的新特性和hibernate3.3做区别 1.数据库方言设置 <property name=”dialect”>org.hibernate.dial ...
- Caused by: java.lang.ClassNotFoundException: org.hibernate.service.jta.platform.spi.JtaPlatform
1.错误描述 2014-7-12 22:08:01 org.hibernate.tool.hbm2ddl.SchemaUpdate execute INFO: HHH000232: Schema up ...
- 总结Hibernate4.1+版本与Hibernate3.3+版本区别
利用休假时间好好学习了当今流行的ORMapping框架-Hibernate,看完了马士兵老师经典的Hibernate视频教程,也算是小小入门了吧. 马老师在讲课中使用的Hibernate版本是3.3. ...
- java.lang.NoClassDefFoundError: org/hibernate/service/ServiceRegistry] 类似问题
使用Hibernate时出现以上错误,在Java Project中运行无误,但是来到Dynamic Web Project中却出现了如下错误: hibernate 报错:java.lang.NoCla ...
- 【Hibernate】版本错误 org/hibernate/Query : Unsupported major.minor version 52.0
报错原因:jdk1.7不支持 hibernate的最新版本5.2.0,把hibernate的版本换成5.1.3或更早的版本. 补充:mysql-connector-java-6.0.x也不被hiber ...
随机推荐
- Hadoop本地安装
安装JDK卸载已经安装的JDK安装sun公司的JDK安装Hadoop(本地方式)解压并安装启动测试程序 安装JDK 卸载已经安装的JDK rpm -qa|grep jdk rpm -qa|grep g ...
- L198
One of the most common birth defects throughout the world is a cleft lip. Babies born with a cleft l ...
- 在.NET开发中的单元测试工具之——NUnit
NUnit介绍 NUnit是一个专门针对于.NET来写的单元测试框架,它是xUnit体系中的一员,在xUnit体系中还有针对Java的JUnit和针对C++的CPPUnit,在开始的时候NUnit和x ...
- 启动tornado项目,hello world
新建一个env虚拟环境 mkvirtualenv toenv 在虚拟环境中安装tornado workon toenv pip install tornado 在D盘中新建tornado项目文件夹,就 ...
- 接口测试工具Soapui5.1.2参数化之Properties20150924
上次用天气预报的来给大家演示了下如何创建项目.测试套件.测试用例的操作,今天演示下如何参数化,废话不多说,跟着操作即可: 1.在一个用例中有两个步骤,我们想将第一个步骤中的响应中的值,传入第二个步骤中 ...
- 量化投资策略:常见的几种Python回测框架(库)
量化投资策略:常见的几种Python回测框架(库) 原文地址:http://blog.csdn.net/lawme/article/details/51454237 本文章为转载文章.这段时间在研究量 ...
- 在Android中来修改SQL里面的权限和显示内容
1.在Android中建立了一个数据库. 然后要知道存储数据库的路劲.得到路劲然后进入cmd里面进到 手机终端. 2.利用splite3来显示数据库里面的东西. 3.利用chmod来修改数据库文件的权 ...
- sublime text2下配置c++
今天安装了sublime text2,真是编辑神器,不再用notepad了. 笔记本上没有c++运行环境,用编辑器既轻巧,又方便,VS太臃肿了. 要在sublime text2 下运行c++程序,需要 ...
- Log4j(一):Log4j将日志信息写入数据库
前言 为了监听一些数据的采集等功能,需要随时监听设备的状态,所以需要运行的时候将日志打入到数据库中. 正文 第一步: 首先是jar包,由于我使用的是springboot,所以,在springboot- ...
- vi/vim使用进阶: 在VIM中使用GDB调试 – 使用vimgdb
vi/vim使用进阶: 在VIM中使用GDB调试 – 使用vimgdb << 返回vim使用进阶: 目录 本节所用命令的帮助入口: :help vimgdb 在UNIX系统最初设计时,有一 ...