欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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

程序员文章站 2022-04-14 09:14:25
...

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