package com.sun.java.utils;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;
/**
* @author Dell
* hibernate使用注解时的工具类
*
*/
public class HibernateAnnoaUtils {
private static SessionFactory factory;
// 静态代码块
static {
Configuration cfg = new AnnotationConfiguration().configure();
factory = cfg.buildSessionFactory();
}
// 获取SessionFactory的方法
public SessionFactory getSessionFactory() {
return factory;
}
// 获取session的方法
public Session getSession() {
return factory.openSession();
}
// 私有化构造函数
private HibernateAnnoaUtils() {
}
}