使用Hibernate官方文档上的下面代码进行測试时报出这个异常。

org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set

package org.hibernate.tutorial.util;

import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration; public class HibernateUtil { private static final SessionFactory sessionFactory = buildSessionFactory(); private static SessionFactory buildSessionFactory() {
try {
// Create the SessionFactory from hibernate.cfg.xml
new Configuration().configure().buildSessionFactory(
new StandardServiceRegistryBuilder().build() );
}
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;
} }

后来改动成旧版本号的例如以下代码异常消失:

Configuration cfg = new Configuration();
SessionFactory sf = cfg.configure().buildSessionFactory();
Session session = sf.openSession();

可是无參的buildSessionFactory方法在新版本号中已经不推荐使用了,最后找到了解决的方法:

Configuration cfg = new Configuration().configure();
sessionFactory = cfg.buildSessionFactory(new StandardServiceRegistryBuilder().applySettings(cfg.getProperties()).build());

亲測不会再出现这个异常了。

[Hibernate]Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set的更多相关文章

  1. 【方言】Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set

    Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set 几种 方言配置差异 <?xml v ...

  2. 【Hibernate】Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set

    今天用hibernate框架写crm项目时遇到报错: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' n ...

  3. org.hibernate.PropertyValueException: not-null property references a null or transient value:

    org.hibernate.PropertyValueException: not-null property references a null or transient value: com.bj ...

  4. org.hibernate.PropertyValueException: not-null property references a null or transient value: model.

    今天在写一个SSH整合的项目时,首先将数据库操作部分单独分离出来,写完后使用Junit进行測试,经过測试.发现没有不论什么问题,对数据库中的内容进行增删改查没有问题,可是将他整合到SSH的项目中时,报 ...

  5. [原创]java WEB学习笔记77:Hibernate学习之路---Hibernate 版本 helloword 与 解析,.环境搭建,hibernate.cfg.xml文件及参数说明,持久化类,对象-关系映射文件.hbm.xml,Hibernate API (Configuration 类,SessionFactory 接口,Session 接口,Transaction(事务))

    本博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用 内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系. 本人互联网技术爱 ...

  6. Hibernate注解映射sequence时出现无序增长问题+hibernate 映射 oracle ID自动增长:

    Hibernate注解映射sequence时出现无序增长问题+hibernate 映射 oracle ID自动增长: 通过Hibernate注解的方式映射oracel数据库的sequence主键生成器 ...

  7. hibernate出现 org.hibernate.PropertyNotFoundException: field [departmen] not found on cn.itcast.hibernate.domain.Employee1错误

    hibernate出现 org.hibernate.PropertyNotFoundException: field [departmen] not found on cn.itcast.hibern ...

  8. hibernate添加数据,默认字段为null的问题解决

    数据库中的一个字段默认为0,但是在用hibernate的添加之后,默认字段竟然不是0,为NULL. 查了一下.发现想要让默认字段生效.需要在*.hbm.xml添加一些参数,如下.(红色部分) dyna ...

  9. Hibernate JPA 动态criteria语句针对null查询条件的特殊处理

    最近原Hibernate项目需要添加一个条件,结构有点类似下面的格式,学生和房间是多对一的关系,现在要查询所有没有房间的学生. Class Student{ @ManyToOne Room room; ...

随机推荐

  1. HDU 5372 Segment Game

    /** 多校联合2015-muti7-1004 <a target=_blank href="http://acm.hdu.edu.cn/showproblem.php?pid=537 ...

  2. validate命令---rman进行备份和回复的验证

    rman作为oracle备份与恢复工具,为我们提供了强大的功能.当中包含对数据文件的物理和逻辑检測以及备份文件的有效性检測. 首先.来看一下rman对数据文件的检測. 我们知道,rman在备份数据时, ...

  3. Bash脚本中的操作符

    一.文件測试操作符 假设以下的条件成立将会返回真. -e 文件存在 -a 文件存在 这个选项的效果与-e同样. 可是它已经被"弃用"了, 而且不鼓舞使用. -f 表示这个文件是一个 ...

  4. 0x07 贪心

    被虐爆了...贪心这种玄学东西还可以证吗??除了范围缩放算是可以想想比较经典(倍增第一题?)... poj3614:这道题想了很久,并没有想到是把minSPF按大到小排序,一直的思想是小的就小到大排序 ...

  5. 33.Qt模型与视图

    #include "mainwindow.h" #include <QApplication> #include <QAbstractItemModel> ...

  6. centos + nodejs + egg2.x 开发微信分享功能

    本文章发到掘金上,请移步阅读: https://juejin.im/post/5cf10b02e51d45778f076ccd

  7. 多元一次方程解法 C++

    #include<iostream> #include<math.h> #include<fstream> #include<stdlib.h> usi ...

  8. 服务端 | Nodejs 学习笔记(一)

    Node.js 前言: 2009年面世 nodejs.org 官网 https://www.npmjs.com/ 模块社区 github.com 仓库 stackoverflow.com  问答社区 ...

  9. Android和Html的简单交互

    ---恢复内容开始--- 1.通过WebView加载Html界面.在android studio中html放在assets中. 但是默认的并不存在这个文件夹,创建过程是 2.创建后简单实现下,js调用 ...

  10. CoordinatorLayout:android之ScrollingActivity

    1.效果图 2.新建SrcollingActivity后生成代码为: <?xml version="1.0" encoding="utf-8"?> ...