zoukankan      html  css  js  c++  java
  • [Hibernate]Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set

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


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



  • 相关阅读:
    POJ
    POJ
    POJ1753 Flip Game(位运算+暴力枚举)
    20160326 javaweb 请求转发和请求包含
    将博客搬至CSDN
    javaweb 中的乱码问题
    20160324 javaweb 之request
    20160322 javaweb 学习笔记--response验证码实现
    20160322 javaweb 学习笔记--response 重定向
    深入分析 Java 中的中文编码问题 (文章来自网络)
  • 原文地址:https://www.cnblogs.com/gavanwanggw/p/7067098.html
Copyright © 2011-2022 走看看