关于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 ...
随机推荐
- 054——VUE中vue-router之实例讲解定义一下单页面路由
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 前端常用框架和js插件 UI组件等
前言:写这个随笔,是记录一下工作以来用到的各种框架.以免日后忘记: JS库: 1. jquery.js 2. zepto.js ----jquery的精简版,专门用于手机上的,但是zepto主体默认是 ...
- 『转』Panda Antivirus Pro 2014 – 免费6个月
Panda Antivirus Pro 2014 为您的计算机提供了最简单的使用和最直观的保护.最近,Panda公司和 softonic公司合作推出免费半年版本活动地址:点此进入点击“Kostenlo ...
- 2018.12.20 L195
Every Brazilian, including current and former members of the armed forces, will have to compromise u ...
- ubuntu16 Intellij Idea Install&config
1,下载idea二进制文件,有免费和不免费的. https://www.jetbrains.com/idea/download/#section=linux 2,解压下载文件. tar -xvzf . ...
- 新转移注意(caffe):ImportError: libcudart.so.7.0: cannot open shared object file: No such file or directory
https://github.com/NVIDIA/DIGITS/issues/8 For this error ImportError: libcudart.so.7.0: cannot open ...
- Windows同时安装python3和python2
Windows同时安装python3和python2 https://www.cnblogs.com/shanhua-fu/p/6912683.html Windows7 下python3和pytho ...
- salesforce linghtning component 自动添加标准style css样式
Your app automatically gets Lightning Design System styles if it extends force:slds <aura:applic ...
- 490 - Rotating Sentences
Rotating Sentences In ``Rotating Sentences,'' you are asked to rotate a series of input sentences ...
- TimescaleDB 简单试用
TimescaleDB 是一个对于pg进行了改造的时序数据库 安装测试使用docker 安装&&运行 docker run -d --name timescaledb -p 5432: ...