把网线拔掉几分钟后再连上,hibernate就再也不能连接到数据库,这个问题怎么解决???

时间:2022-10-08 00:42:18
下面是后台输出的错误信息:
Hibernate: select regiondef0_.REGION_ID as REGION1_1_, regiondef0_.NAME as NAME1_, regiondef0_.REGION_TYPE as REGION3_1_, regiondef0_.HOME_ID as HOME4_1_ from MM.REGION_DEF regiondef0_ where regiondef0_.REGION_ID<1000 and regiondef0_.HOME_ID=0
09:43:34,062  WARN JDBCExceptionReporter:71 - SQL Error: 17002, SQLState: null
09:43:34,062 ERROR JDBCExceptionReporter:72 - Io 异常: Connection reset by peer: socket write error
org.hibernate.exception.GenericJDBCException: could not execute query
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:2148)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
at org.hibernate.loader.Loader.list(Loader.java:2024)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:392)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:333)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1114)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at com.newland.bias.dao.BaseHibernateDAO.getDataList(BaseHibernateDAO.java:269)
at com.newland.bias.mgmt.RegionDefMgmt.getRegionList(RegionDefMgmt.java:33)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at net.buffalo.service.invoker.burlap.BurlapInvoker.invoke(BurlapInvoker.java:208)
at net.buffalo.service.BuffaloWorker.processRequest(BuffaloWorker.java:66)
at net.buffalo.web.servlet.ApplicationServlet.doRequest(ApplicationServlet.java:121)
at net.buffalo.web.servlet.ApplicationServlet.doPost(ApplicationServlet.java:89)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:868)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:663)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)
Caused by: java.sql.SQLException: Io 异常: Connection reset by peer: socket write error
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:333)
at oracle.jdbc.driver.OracleStatement.<init>(OracleStatement.java:389)
at oracle.jdbc.driver.OracleStatement.<init>(OracleStatement.java:413)
at oracle.jdbc.driver.OraclePreparedStatement.<init>(OraclePreparedStatement.java:119)
at oracle.jdbc.driver.OraclePreparedStatement.<init>(OraclePreparedStatement.java:92)
at oracle.jdbc.driver.OracleConnection.privatePrepareStatement(OracleConnection.java:950)
at oracle.jdbc.driver.OracleConnection.prepareStatement(OracleConnection.java:802)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:497)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:415)
at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:139)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1561)
at org.hibernate.loader.Loader.doQuery(Loader.java:661)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2145)
... 33 more

7 个解决方案

#1


各位高手有没有好办法解决这个问题啊??????

#2


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

#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="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>

#4


下面是获取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);
    }
    
   
}

#5


用c3p0 上面这样的类要怎么写

#6


<?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>

#7


谢谢 hbwhwang(catmiw的ID已经停用,现在用这个) 用c3p0 解决网络的问题

<property name="hibernate.c3p0.max_statements">50</property>
这个参数具体是什么作用?

#1


各位高手有没有好办法解决这个问题啊??????

#2


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

#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="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>

#4


下面是获取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);
    }
    
   
}

#5


用c3p0 上面这样的类要怎么写

#6


<?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>

#7


谢谢 hbwhwang(catmiw的ID已经停用,现在用这个) 用c3p0 解决网络的问题

<property name="hibernate.c3p0.max_statements">50</property>
这个参数具体是什么作用?