首页 > 代码库 > Caused by: org.hibernate.HibernateException: Connection cannot be null when 'hibernate.dialect' not

Caused by: org.hibernate.HibernateException: Connection cannot be null when 'hibernate.dialect' not

我手动配置hibernate4.3.4,测试的时候出现:

Caused by: org.hibernate.HibernateException: Connection cannot be null when ‘hibernate.dialect‘ not set

我是按照官方文档配置的,但是官方文档的代码好像有点问题

这是官方文档里面的那个工具类的部分代码:return new Configuration().configure().buildSessionFactory(
       new StandardServiceRegistryBuilder().build() );

搞笑的是,官方文档时没有哪个return,感觉是不是太粗心了

。。。。后来看网上的文档,自己有改了一下,可以了

下面是正确的代码:

Configuration configuration = new Configuration().configure();
            ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
            SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);
            return sessionFactory;