Hibernate是否弃用了buildSessionFactory()配置方法 [英] Is the buildSessionFactory() Configuration method deprecated in Hibernate
问题描述
当我将Hibernate版本从3.6.8更新到4.0.0时,在此行中收到有关已弃用的方法buildSessionFactory()
的警告:
When I updated the Hibernate version from 3.6.8 to 4.0.0, I got a warning about deprecated method buildSessionFactory()
in this line:
private static final SessionFactory sessionFactory =
new Configuration().configure().buildSessionFactory();
Javadoc建议使用另一种方法
the Javadoc recommends using another method
buildSessionFactory(ServiceRegistry serviceRegistry)
but in the documentation I found deprecated variant :(
您能帮我解决这个小小的误会吗?
Can you help me with this little misunderstanding?
推荐答案
是不推荐使用.将您的SessionFactory替换为以下内容:
Yes it is deprecated. Replace your SessionFactory with the following:
在休眠4.0、4.1、4.2
private static SessionFactory sessionFactory;
private static ServiceRegistry serviceRegistry;
public static SessionFactory createSessionFactory() {
Configuration configuration = new Configuration();
configuration.configure();
ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(
configuration.getProperties()). buildServiceRegistry();
sessionFactory = configuration.buildSessionFactory(serviceRegistry);
return sessionFactory;
}
更新:
在 Hibernate 4.3 中,已弃用了ServiceRegistryBuilder .请改用以下内容.
In Hibernate 4.3 ServiceRegistryBuilder is deprecated. Use the following instead.
serviceRegistry = new StandardServiceRegistryBuilder().applySettings(
configuration.getProperties()).build();
这篇关于Hibernate是否弃用了buildSessionFactory()配置方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!