资源简介
hibernate调用存储过程hibernate调用存储过程
代码片段和文件信息
package com.jason.entity;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.cfg.Configuration;
public class HibernateSessionFactory {
private static String CONFIG_FILE_LOCATION = “/hibernate.cfg.xml“;
private static final ThreadLocal threadLocal = new ThreadLocal();
private static Configuration configuration = new Configuration();
private static org.hibernate.SessionFactory sessionFactory;
private static String configFile = CONFIG_FILE_LOCATION;
static {
try {
configuration.configure(configFile);
sessionFactory = configuration.buildSessionFactory();
} catch (Exception e) {
System.err
.println(“%%%% Error Creating SessionFactory %%%%“);
e.printStackTrace();
}
}
private HibernateSessionFactory() {
}
/**
* Returns the ThreadLocal Session instance. Lazy initialize
* the SessionFactory
if needed.
*
* @return Session
* @throws HibernateException
*/
public static Session getSession() throws HibernateException {
Session session = (Session) threadLocal.get();
if (session == null || !session.isOpen()) {
if (sessionFactory == null) {
rebuildSessionFactory();
}
session = (sessionFactory != null) ? sessionFactory.openSession()
: null;
threadLocal.set(session);
}
return session;
}
/**
* Rebuild hibernate session factory
*
*/
public static void rebuildSessionFactory() {
try {
configuration.configure(configFile);
sessionFactory = configuration.buildSessionFactory();
} catch (Exception e) {
System.err
.println(“%%%% Error Creating SessionFactory %%%%“);
e.printStackTrace();
}
}
/**
* Close the single hibernate session instance.
*
* @throws HibernateException
*/
public static void closeSession() throws HibernateException {
Session session = (Session) threadLocal.get();
threadLocal.set(null);
if (session != null) {
session.close();
}
}
/**
* return session factory
*
*/
public static org.hibernate.SessionFactory getSessionFactory() {
return sessionFactory;
}
/**
* return session factory
*
* session factory will be rebuilded in the next call
*/
public static void setConfigFile(String configFile) {
HibernateSessionFactory.configFile = configFile;
sessionFactory = null;
}
/**
* return hibernate configuration
*
*/
public static Configuration getConfiguration() {
return configuration;
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 693 2008-12-18 11:43 mysqlproduce\.classpath
文件 457 2008-12-18 10:33 mysqlproduce\.myhibernatedata
文件 309 2008-12-18 11:42 mysqlproduce\.myme
文件 1216 2008-12-18 10:33 mysqlproduce\.project
文件 2717 2008-12-18 11:43 mysqlproduce\src\com\jason\entity\HibernateSessionFactory.java
文件 1931 2008-12-18 11:35 mysqlproduce\src\com\jason\entity\test.java
文件 937 2008-12-18 11:33 mysqlproduce\src\com\jason\entity\user.hbm.xm
文件 523 2008-12-18 10:35 mysqlproduce\src\com\jason\entity\User.java
文件 1007 2008-12-18 10:56 mysqlproduce\src\hibernate.cfg.xm
文件 1747 2008-12-18 11:39 mysqlproduce\user.sql
文件 834 2008-12-18 10:29 mysqlproduce\WebRoot\index.jsp
文件 39 2008-12-18 10:29 mysqlproduce\WebRoot\me
文件 2479 2008-12-18 11:44 mysqlproduce\WebRoot\WEB-INF\classes\com\jason\entity\HibernateSessionFactory.class
文件 2946 2008-12-18 11:43 mysqlproduce\WebRoot\WEB-INF\classes\com\jason\entity\test.class
文件 951 2008-12-18 11:43 mysqlproduce\WebRoot\WEB-INF\classes\com\jason\entity\User.class
文件 937 2008-12-18 11:33 mysqlproduce\WebRoot\WEB-INF\classes\com\jason\entity\user.hbm.xm
文件 1007 2008-12-18 10:56 mysqlproduce\WebRoot\WEB-INF\classes\hibernate.cfg.xm
文件 381 2008-12-18 10:29 mysqlproduce\WebRoot\WEB-INF\web.xm
目录 0 2008-12-18 11:44 mysqlproduce\WebRoot\WEB-INF\classes\com\jason\entity
目录 0 2008-12-18 11:44 mysqlproduce\WebRoot\WEB-INF\classes\com\jason
目录 0 2008-12-18 11:44 mysqlproduce\src\com\jason\entity
目录 0 2008-12-18 11:44 mysqlproduce\WebRoot\WEB-INF\classes\com
目录 0 2008-12-18 11:44 mysqlproduce\src\com\jason
目录 0 2008-12-18 11:44 mysqlproduce\WebRoot\WEB-INF\classes
目录 0 2008-12-18 11:44 mysqlproduce\WebRoot\WEB-INF\lib
目录 0 2008-12-18 11:44 mysqlproduce\src\com
目录 0 2008-12-18 11:44 mysqlproduce\WebRoot\me
目录 0 2008-12-18 11:44 mysqlproduce\WebRoot\WEB-INF
目录 0 2008-12-18 11:44 mysqlproduce\.myeclipse
目录 0 2008-12-18 11:44 mysqlproduce\src
............此处省略5个文件信息
- 上一篇:PIC单片机延时计算器
- 下一篇:大一c 课程设计简单的图书管理系统
评论
共有 条评论