使用Hibernate中出现的小错误org.hibernate.service.spi.ServiceException

在使用Hibernate是发现如下的错误:

Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested
service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]

原因是在建立SessionFactoy

private static SessionFactory sf;
    static{
        sf=new Configuration().buildSessionFactory();
    }

没有加入config()。正确的方法应该是

private static SessionFactory sf;
    static{
        sf=new Configuration().configure().buildSessionFactory();
    }
原文地址:https://www.cnblogs.com/dengkaien/p/7896844.html