专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > Java Exception

hibernate ExceptionSession is closed问题?

发布时间:2010-06-05 12:34:25 文章来源:www.iduyao.cn 采编人员:星星草

源码:
  1.SessionFactory 类
  package com.tangjie.hibernnate;
 
  import net.sf.hibernate.HibernateException;
  import net.sf.hibernate.Session;
  import net.sf.hibernate.cfg.Configuration;
 
  /**
  * Configures and provides access to Hibernate sessions, tied to the
  * current thread of execution. Follows the Thread Local Session
  * pattern, see {@link http://hibernate.org/42.html}.
  */
  public class SessionFactory {
 
  /**
  * Location of hibernate.cfg.xml file.
  * NOTICE: Location should be on the classpath as Hibernate uses
  * #resourceAsStream style lookup for its configuration file. That
  * is place the config file in a Java package - the default location
  * is the default Java package.<br><br>
  * Examples: <br>
  * <code>CONFIG_FILE_LOCATION = "/hibernate.conf.xml".
  * CONFIG_FILE_LOCATION = "/com/foo/bar/myhiberstuff.conf.xml".</code>
  */
  private static String CONFIG_FILE_LOCATION = "/hibernate.cfg.xml";
 
  /** Holds a single instance of Session */
  private static final ThreadLocal threadLocal = new ThreadLocal();
 
  /** The single instance of hibernate configuration */
  private static final Configuration cfg = new Configuration();
 
  /** The single instance of hibernate SessionFactory */
  private static net.sf.hibernate.SessionFactory sessionFactory;
 
  /**
  * Returns the ThreadLocal Session instance. Lazy initialize
  * the <code>SessionFactory</code> if needed.
  *
  * @return Session
  * @throws HibernateException
  */
  public static Session currentSession() throws HibernateException {
  Session session = (Session) threadLocal.get();
 
  if (session == null) {
  if (sessionFactory == null) {
    try {
    cfg.configure(CONFIG_FILE_LOCATION);     

友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: