hibernatesessionhelper.java

来自「struts+hibernate3的源程序」· Java 代码 · 共 62 行

JAVA
62
字号
package org.helpsoft;

import com.helpsoft.util.log.*;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.Query;


import org.helpsoft.entity.hy.*;
import org.helpsoft.entity.hyklx.*;
import org.helpsoft.entity.hyxf.*;
import org.helpsoft.entity.sp.*;
import org.helpsoft.entity.splb.*;
import org.helpsoft.entity.czk.*;
import org.helpsoft.entity.tx.*;
import org.helpsoft.entity.zkk.*;
import org.helpsoft.entity.xfmx.*;


/**
 * This class is a Helper for the Hibernate Sessions.
 *
 * @author  cao guangxin - www.relationinfo.com
 */
public class HibernateSessionHelper {

    /**
     * The logger
     */
    private static Logger log = LogService.getLogger(HibernateSessionHelper.class);

   /**
    * The Hibernate configuration.
    */
   private static Configuration cfg;

   /**
    * The Hibernate session factory.
    */
   private static SessionFactory sf;

    static {
       try {
        cfg = new Configuration().configure();
        sf = cfg.buildSessionFactory();
       } catch (Exception e) {
          log.fatal("Error while configuring the hibernate beans", e);
       }
    }

    /**
    * Get a hibernate session.
    */
    public static Session getHibernateSession() throws Exception
    {
        Session session = sf.openSession();
        return session;
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?