日期:2014-05-17 浏览次数:20737 次
package com.usensor.hibernate.util;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class HibernateUtil {
private static SessionFactory sessionFactory;
public HibernateUtil(){}
static{
Configuration cfg = new Configuration();
cfg.configure();//cfg.configure("Hibernate.cfg.xml"),用于读取配置文件
sessionFactory = cfg.buildSessionFactory();
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
public static Session getSession(){
return sessionFactory.openSession();
}
public static void closeSession(Session session){
if(session!=null){
if(session.isOpen())
session.close();
}
}
}
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>
<session-factory>
<property name="proxool.pool_alias">proxoolPool</property>
<property name="proxool.xml">WEB-INF/proxoolconf.xml</property>
<property name="hibernate.proxool.existing_pool">true</property>
<property name="connection.provider_class">
org.hibernate.connection.ProxoolConnectionProvider
</property>
<property name="connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="connection.characterEncoding">UTF-8</property>
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="connection.url"></property>
<mapping resource="com/usensor/user/entity/UsrUser.hbm.xml" />
<mapping resource="com/usensor/user/entity/UsrAdmin.hbm.xml" />
<mapping resource="com/usensor/feed/entity/FeedInfo.hbm.xml" />
<mapping resource="com/usensor/feed/entity/FeedDatastream.hbm.xml" />
<mapping resource="com/usensor/feed/entity/FeedData.hbm.xml" />
<mapping resource="com/usensor/utils/entity/MngNotice.hbm.xml" />
<mapping resource="com/usensor/user/entity/UsrFavfeed.hbm.xml" />
<mapping resource="com/usensor/user/entity/UsrMsg.hbm.xml"