创建Hibernate SessionFactory

时间:2016-05-05 10:07:40

标签: java hibernate

我收到错误:ServiceRegistryBuilder无法解析为某种类型。请帮我解决问题:

 import javax.imageio.spi.ServiceRegistry;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class HibernateConnectionUtil {

    private static HibernateConnectionUtil instance = null;

       private static SessionFactory sessionFactory;
       private static ServiceRegistry serviceRegistry;

       private HibernateConnectionUtil(){
            Configuration configuration = new Configuration();
            configuration.configure();
            serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
            sessionFactory = configuration.buildSessionFactory(serviceRegistry);
       }

       public static HibernateConnectionUtil getInstance(){
            if(instance == null){
                instance  = new HibernateConnectionUtil();
            }
            return instance;
       }

       public static SessionFactory getSessionFactory() {
            return sessionFactory;
       }}

0 个答案:

没有答案