This is my HibernateUtil file.
/* * To change this template, choose Tools | Templates * and open the template in the editor. */
package javabean;
import java.io.FileInputStream; import java.io.InputStream; import org.hibernate.SessionFactory; import java.util.PropertyResourceBundle; import java.util.ResourceBundle; import org.hibernate.cfg.Configuration;
/** * Hibernate Utility class with a convenient method to get Session Factory object. * * @author Administrator */ public class HibernateUtil { private static final SessionFactory sessionFactory;
static { try{ // Create the SessionFactory from standard (hibernate.cfg.xml) // config file. String configfile=System.getProperty("user.dir")+"\\"+"GENURN.conf"; /*------------------ to see the path of the configuration file---------------*/ // System.out.println("config file is:"+configfile); InputStream in = new FileInputStream(configfile); ResourceBundle resource = new PropertyResourceBundle(in); Configuration cfg = new Configuration() .setProperty("hibernate.connection.url", resource.getString("hibernate.connection.url")) .setProperty("hibernate.connection.password", resource.getString("DbObject.OraclePassword")) .setProperty("hibernate.connection.username", resource.getString("DbObject.OracleUser")); sessionFactory = cfg.configure().buildSessionFactory();
} catch (Throwable ex) { // Log the exception. System.err.println("Initial SessionFactory creation failed." + ex); throw new ExceptionInInitializerError(ex); } }
public static SessionFactory getSessionFactory() { return sessionFactory; } }
|