org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine

来源:互联网 发布:unity3d麻将胡牌 编辑:程序博客网 时间:2024/05/17 23:52

学习hibernate过程中遇到了不少问题,这也是作为一个菜鸟程序员一定会遇到的问题,就是粗心,这不,又出事了。
这是在编写hibernate测试的时候遇到的。
问题:以下就粘贴主要错误提示
org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]

可能原因:Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when ‘hibernate.dialect’ not set

错误原因:

public class HibernateTest{    @Test    public void test(){        //1.加载配置文件        Configuration configuration = new Configuration();        //如果不使用configure()方法,这时hibernate会在classpath下面寻找hibernate.properties文件,如果没有找到该文件,系统会打印如下信息并抛出HibernateException异常。        //2.创建SessionFactory工厂对象        SessionFactory sessionFactory = configuration.buildSessionFactory();        //3.获取Session对象        Session session = sessionFactory.getCurrentSession();        //4.执行操作        Student student = new Student("张三",20);        session.save(student);    }}

解决方法:
直接写上这行代码就行了
Configuration configuration = new Configuration().configure();
//因为这个位置漏写了得到.configure();产生了以下错误

总结:问题虽小,但也是可以避免的,这样也能为编程节约不少时间,如果问题能够避免,为什么还要去自找呢?归根到底,还是粗心惹的祸,所以敲代码还需谨慎啊。

0 0
原创粉丝点击