资源简介

应用hibernate+servlet+jsp开发的超市账单管理,适合初学者学习和掌握hibernate+servlet+jsp开发

资源截图

代码片段和文件信息

package com.cn;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.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 HibernateSessionFactory {

    /** 
     * Location of hibernate.cfg.xml file.
     * Location should be on the classpath as Hibernate uses  
     * #resourceAsStream style lookup for its configuration file. 
     * The default classpath location of the hibernate config file is 
     * in the default package. Use #setConfigFile() to update 
     * the location of the configuration file for the current session.   
     */
    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) {
Hibernate

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        856  2012-02-06 19:53  hibernate+servlet+jsp\shopingmarket\.classpath

     文件        556  2012-02-06 19:53  hibernate+servlet+jsp\shopingmarket\.myhibernatedata

     文件        312  2012-02-06 18:37  hibernate+servlet+jsp\shopingmarket\.mymetadata

     文件       1488  2012-02-06 19:53  hibernate+servlet+jsp\shopingmarket\.project

     文件        109  2011-12-07 16:15  hibernate+servlet+jsp\shopingmarket\.settings\com.genuitec.eclipse.ws.prefs

     文件       3207  2012-02-06 19:53  hibernate+servlet+jsp\shopingmarket\src\com\cn\HibernateSessionFactory.java

     文件       7865  2012-02-07 18:45  hibernate+servlet+jsp\shopingmarket\src\demo1\DBOperation.java

     文件       5150  2012-02-06 18:49  hibernate+servlet+jsp\shopingmarket\src\demo1\gydbo.java

     文件       5524  2012-02-06 18:49  hibernate+servlet+jsp\shopingmarket\src\demo1\userdbo.java

     文件       1417  2012-02-06 21:11  hibernate+servlet+jsp\shopingmarket\src\demo2\account.hbm.xml

     文件       1126  2011-12-07 16:15  hibernate+servlet+jsp\shopingmarket\src\demo2\gySecret.java

     文件       1573  2011-12-07 16:15  hibernate+servlet+jsp\shopingmarket\src\demo2\Secret.java

     文件       1216  2011-12-07 16:15  hibernate+servlet+jsp\shopingmarket\src\demo2\userSecret.java

     文件       1117  2011-12-07 16:15  hibernate+servlet+jsp\shopingmarket\src\gyservlet\gychall.java

     文件       1505  2011-12-07 16:15  hibernate+servlet+jsp\shopingmarket\src\gyservlet\gycharuservlet.java

     文件       1456  2011-12-07 16:15  hibernate+servlet+jsp\shopingmarket\src\gyservlet\gychaxunservlet.java

     文件       1050  2011-12-07 16:15  hibernate+servlet+jsp\shopingmarket\src\gyservlet\gydeletservlet.java

     文件       2376  2011-12-07 16:15  hibernate+servlet+jsp\shopingmarket\src\gyservlet\gygengxinservlet.java

     文件       1685  2011-12-07 16:15  hibernate+servlet+jsp\shopingmarket\src\gyservlet\gymodifyservlet.java

     文件        881  2012-02-06 20:26  hibernate+servlet+jsp\shopingmarket\src\hibernate.cfg.xml

     文件       2785  2012-02-06 18:53  hibernate+servlet+jsp\shopingmarket\src\login\loginservlet.java

     文件       1139  2011-12-07 16:15  hibernate+servlet+jsp\shopingmarket\src\servletdemo\chaall.java

     文件       1685  2012-02-06 21:15  hibernate+servlet+jsp\shopingmarket\src\servletdemo\charuservlet.java

     文件       1481  2011-12-07 16:15  hibernate+servlet+jsp\shopingmarket\src\servletdemo\chaxunservlet.java

     文件       1101  2011-12-07 16:15  hibernate+servlet+jsp\shopingmarket\src\servletdemo\deletservlet.java

     文件       2869  2011-12-07 16:15  hibernate+servlet+jsp\shopingmarket\src\servletdemo\gengxinservlet.java

     文件       1703  2012-02-07 17:45  hibernate+servlet+jsp\shopingmarket\src\servletdemo\modifyservlet.java

     文件       1101  2011-12-07 16:15  hibernate+servlet+jsp\shopingmarket\src\userservlet\userchaall.java

     文件       1562  2011-12-07 16:15  hibernate+servlet+jsp\shopingmarket\src\userservlet\usercharuservlet.java

     文件       1269  2011-12-07 16:15  hibernate+servlet+jsp\shopingmarket\src\userservlet\userchaxunservlet.java

............此处省略114个文件信息

评论

共有 条评论