首页 > 代码库 > hibernate 5 创建 Session 时,所需的ServiceRegistry

hibernate 5 创建 Session 时,所需的ServiceRegistry

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