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
时间: 2024-11-04 11:24:39