SfUtil.SfUtil.java Source code

Java tutorial

Introduction

Here is the source code for SfUtil.SfUtil.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 SfUtil;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;

/**
 * Hibernate Utility class with a convenient method to get Session Factory
 * object.
 *
 * @author DeadMeat
 */
public class SfUtil {

    public SessionFactory SfUtil() {
        Configuration config = new Configuration().configure("hibernate.cfg.xml");
        StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder()
                .applySettings(config.getProperties());

        SessionFactory sf = config.buildSessionFactory(builder.build());

        return sf;
    }
}