Skip to content

Instantly share code, notes, and snippets.

@pengju
Created July 24, 2012 02:31
Show Gist options
  • Save pengju/3167647 to your computer and use it in GitHub Desktop.
Save pengju/3167647 to your computer and use it in GitHub Desktop.
hibernate中的工具类,生成sessionFactory和session
package com.kaishengit.util;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class HibernateUtil {
private HibernateUtil() {};
private static Configuration cfg = new Configuration().configure();
private static SessionFactory factory = cfg.buildSessionFactory();
public static SessionFactory getFactory (){
return factory;
}
public static Session getSession () {
return factory.getCurrentSession();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment