Hibernate是否弃用了buildSessionFactory()配置方法 [英] Is the buildSessionFactory() Configuration method deprecated in Hibernate

查看:321
本文介绍了Hibernate是否弃用了buildSessionFactory()配置方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我将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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆