hibernate的文档也会偷懒:Access to DialectResolutionInfo cannot be null when ‘hibernate.dialect’ not set

配置hibernate4的SessionFactory,按照文档配置完毕,总是下面的报错,无法创建factory:

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

将hbm.cfg.xml中的dialect改成了hibernate.dialect还是不行,嘿,怎么肥事…还解决不了了么。

然后一阵谷歌,发现原来是hibernate的文档没有更新…下面是SessionFactory的生成方法:

Configuration configuration = new Configuration().configure("hbm.cfg.xml");
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
        .applySettings(configuration.getProperties()).build(); // 就是少了applySettings
SessionFactory factory = configuration.buildSessionFactory(serviceRegistry);

估计新版本需要要将配置应用到serviceRegistry上才行吧,然后文档就这么埋了坑。