Package util

Source Code of util.HibernateUtil

package util;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class HibernateUtil {

  private static String username = "";
  private static String password = "";
  private static SessionFactory sessionFactory;

   

    public static SessionFactory getSessionFactory() {
      if(sessionFactory == null){
        try {
                // Create the SessionFactory from hibernate.cfg.xml
              Configuration config = new Configuration().configure();
              config.setProperty("hibernate.connection.username", username);
              config.setProperty("hibernate.connection.password", password);
             
              sessionFactory = config.buildSessionFactory();
            } catch (Throwable ex) {
                // Make sure you log the exception, as it might be swallowed
                System.err.println("Initial SessionFactory creation failed." + ex);
                throw new ExceptionInInitializerError(ex);
            }
      }
        return sessionFactory;
    }
   
    public static void initialize(String username, String password){
      HibernateUtil.username = username;
      HibernateUtil.password = password;
     
    }

}
TOP

Related Classes of util.HibernateUtil

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.