码迷,mamicode.com
首页 > Web开发 > 详细

hibernate 5 创建 Session 时,所需的ServiceRegistry

时间:2016-12-22 00:44:29      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:hibernate serviceregistry serviceregistrybuilder

hibernate 5 创建 Session,代码如下:


SessionFactory factory = null;

Configuration configuration = new Configuration().configure();

configuration.addClass(News.class);

ServiceRegistry registry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();

factory = configuration.buildSessionFactory(registry);

Session session = factory.openSession();


注意:

与之前版本不同的:

1)

    configuration.addClass(News.class);

2)

    ServiceRegistry的实现需用StandardServiceRegistryBuilder

    之前版本用的是 ServiceRegistryBuilder


本文出自 “程序员瑞欣” 博客,请务必保留此出处http://rayshine.blog.51cto.com/6941801/1884823

hibernate 5 创建 Session 时,所需的ServiceRegistry

标签:hibernate serviceregistry serviceregistrybuilder

原文地址:http://rayshine.blog.51cto.com/6941801/1884823

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!