读书人

hibernate施用注解时的工具类

发布时间: 2012-12-18 12:43:41 作者: rapoo

hibernate使用注解时的工具类

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() {

}
}

读书人网 >软件架构设计

热点推荐