问答详情
源自:2-5 session详解(上)

求告知,hibernate错误

org.hibernate.service.ServiceRegistryBuilder cannot be cast to org.hibernate.service.ServiceRegistry 这个是为什么啊??

提问者:慕容7724642 2017-07-18 15:50

个回答

  • 雅俗青年
    2017-07-19 09:44:29
    已采纳

    5版本导入更换为:
    import org.hibernate.boot.registry.StandardServiceRegistryBuilder;

    在4版本中
    Configuration conf = new Configuration().configure();
    ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(conf.getProperties()).buildServiceRegistry();
    SessionFactory sf = conf.buildSessionFactory(serviceRegistry);

    在5版本的Hibernate中,buildServiceReguistry()方法被替换了,用如下方法:
    ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(conf.getProperties()).build();