数据源用的是什么?
如果是JDBC,不要用HIBERNATE自带的连接池,可以用c3p0

解决方案 »

  1.   

    <?xml version='1.0' encoding='GB18030'?>
    <!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="connection.username">mm</property>
        <property name="connection.url">jdbc:oracle:thin:@127.0.0.1:1521:hdb</property>
        <property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>  
        <property name="connection.password">mm</property>
        <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
        <property name="show_sql">true</property>
        
        <mapping resource="pojo/Test.hbm.xml"></mapping>      </session-factory>
    </hibernate-configuration>
      

  2.   

    下面是获取session的类package dao;import org.hibernate.*;
    import org.hibernate.cfg.*;public class HibernateUtil {    public static final SessionFactory sessionFactory;    static {
            try {  
                // Create the SessionFactory from hibernate.cfg.xml
                sessionFactory = new Configuration().configure().buildSessionFactory();
            } catch (Throwable ex) {
                // Make sure you log the exception, as it might be swallowed
                System.err.println("Initial SessionFactory creation failed." + ex);
                throw new ExceptionInInitializerError(ex);
            }
        }    public static final ThreadLocal session = new ThreadLocal();    public static Session currentSession() throws HibernateException {
            Session s = (Session) session.get(); 
            // Open a new Session, if this thread has none yet
            if (s == null) {
            
             //rebuildSessionFactory();
                s = sessionFactory.openSession();           
                // Store it in the ThreadLocal variable
                session.set(s);
            }
           
            return s;
        }    public static void closeSession() throws HibernateException {
            Session s = (Session) session.get();
            if (s != null)
                s.close();
            session.set(null);
        }
        
       
    }
      

  3.   

    <?xml version='1.0' encoding='GB18030'?>
    <!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="dialect">org.hibernate.dialect.Oracle9Dialect</property>  
        <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
        <property name="connection.url">jdbc:oracle:thin:@127.0.0.1:1521:hdb</property>
        <property name="connection.username">mm</property>
        <property name="connection.password">mm</property>    <property name="hibernate.c3p0.min_size">5</property>
        <property name="hibernate.c3p0.max_size">20</property>
        <property name="hibernate.c3p0.timeout">1800property>
        <property name="hibernate.c3p0.max_statements">50</property>    <property name="show_sql">true</property>
        
        <mapping resource="pojo/Test.hbm.xml"></mapping>      </session-factory>
    </hibernate-configuration>
      

  4.   

    谢谢 hbwhwang(catmiw的ID已经停用,现在用这个) 用c3p0 解决网络的问题<property name="hibernate.c3p0.max_statements">50</property>
    这个参数具体是什么作用?