bd.ac.seu.labexam.SessionFactorySingleton.java Source code

Java tutorial

Introduction

Here is the source code for bd.ac.seu.labexam.SessionFactorySingleton.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package bd.ac.seu.labexam;

import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;

/**
 *
 * @author kmhasan
 */
public class SessionFactorySingleton {
    private static SessionFactory sessionFactory;
    private static final SessionFactorySingleton instance = new SessionFactorySingleton();

    private SessionFactorySingleton() {
        Configuration configuration = new Configuration();
        configuration.configure();
        ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
                .applySettings(configuration.getProperties()).build();
        sessionFactory = configuration.buildSessionFactory(serviceRegistry);
    }

    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }
}