首页 > 代码库 > [Hibernate]Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
[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());
[Hibernate]Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。