Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (4k points)

When I updated version of Hibernate from 3.6.8.final to 4.0.0.final I got a warning about deprecated method buildSessionFactory() in this line:

private static final SessionFactory sessionFactory =

         new Configuration().configure().buildSessionFactory();

the javadoc recommends use of another method

buildSessionFactory(ServiceRegistry serviceRegistry)

but in the documentation I found deprecated variant :(

Can you help me with this little misunderstanding ?

1 Answer

0 votes
by (46k points)

Yes, it is deprecated. Succeed your SessionFactory with the following:

In Hibernate 4.0, 4.1, 4.2

private static SessionFactory sessionFactory;

private static ServiceRegistry service registry;

public static SessionFactory createSessionFactory() {

    Configuration configuration = new Configuration();

    configuration.configure();

    ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(

            configuration.getProperties()). buildServiceRegistry();

    sessionFactory = configuration.buildSessionFactory(serviceRegistry);

    return sessionFactory;

}

During Hibernate 4.3 ServiceRegistryBuilder is deprecated. Use the following preferably.

serviceRegistry = new StandardServiceRegistryBuilder().applySettings(

            configuration.getProperties()).build();

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...