hibernate4.3版本如何创建SessionFactory的对象

阅读更多

hibernate框架随着版本的不断升级创建SessionFactory对象的方式也在不断的变化。

 

1、4.0之前我记得是如下这样:

Configuration configuration = new Configuration().configure();
		
SessionFactory sessionFactory = configuration.buildSessionFactory();

 

2、4.3之前如下这样:

Configuration configuration = new Configuration().configure();		
		
ServiceRegistry serviceRegistry = new ServiceRegistryBuilder()
                                  .applySettings(configuration.getProperties())
				             .buildServiceRegistry();
	
SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);

 

3、4.3的新用法如下这样:

Configuration configuration = new Configuration().configure();
		
StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder()
                                       .applySettings(configuration.getProperties());

StandardServiceRegistryImpl registry = (StandardServiceRegistryImpl) builder.build();

SessionFactory sessionFactory = configuration.buildSessionFactory(registry);

 

你可能感兴趣的:(hibernate4)