博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[Hibernate]Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
阅读量:6857 次
发布时间:2019-06-26

本文共 1484 字,大约阅读时间需要 4 分钟。

使用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());

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

转载于:https://www.cnblogs.com/gavanwanggw/p/7067098.html

你可能感兴趣的文章
《当程序员的那些狗日日子》(三十一)特殊任务
查看>>
9.10---堆箱子问题(CC150)
查看>>
Spark技术内幕:究竟什么是RDD
查看>>
新功能!从 Dropbox 部署到 Windows Azure 网站
查看>>
指尖上的电商---(10)SolrAdmin中加入多核
查看>>
CCEditBox/CCEditBoxImplAndroid
查看>>
TCP/IP协议栈--IP首部选项字段的分析
查看>>
Kubuntu 初始配置
查看>>
python中列表和元组的操作(结尾格式化输出小福利)
查看>>
用过的一些服务器集成软件
查看>>
一键拨打
查看>>
20120522:ERROR - ORA-12514: TNS: 监听程序当前无法识别连接描述符中请求的服务
查看>>
Maven构建war项目添加版本号
查看>>
更新 手淘 flexible 布局 rem 单位适配问题
查看>>
第三次作业
查看>>
新浪微博登录接口实例
查看>>
wcf技术剖析_会话
查看>>
AngularJS 指令的 Scope (作用域)
查看>>
gitlab的使用
查看>>
iOS 生成本地验证码
查看>>