Method buildSessionFactory type Configuration deprecated

Method buildSessionFactory type Configuration deprecated

The method buildSessionFactory() from the type Configuration is deprecated

With new version of Hibernate 4.0, 4.1, 4.2, 4.3 buildSessionFactory() is deprecated so please use below sample Utility calss to get SessionFactory:

package com.javahonk.util;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;

public class HibernateUtil {
    private static SessionFactory sessionFactory = buildSessionFactory();
    private static ServiceRegistry serviceRegistry;

    private static SessionFactory buildSessionFactory() {
        try {
            Configuration configuration = new Configuration();
            //set path of config file explicitly
            serviceRegistry = new ServiceRegistryBuilder()
            sessionFactory = configuration
            return sessionFactory;
        } catch (Throwable ex) {
            System.err.println("Initial SessionFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex);

    public static SessionFactory getSessionFactory() {
        return sessionFactory;

    public static void shutdown() {

One thought on “Method buildSessionFactory type Configuration deprecated

Leave a Reply

Your email address will not be published. Required fields are marked *

I am not Robot *