几分钟后Hibernate JDBC连接中断

时间:2018-07-20 12:43:21

标签: java mysql hibernate java-ee

几分钟后,出现此错误。当我执行另一个查询时,它工作正常。

这是错误:

javax.persistence.PersistenceException: org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC Connection
    org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:149)
    org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:157)
    org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1423)
    Dao.implementation.MessageDaoImp.findAllbyid(MessageDaoImp.java:39)
    org.apache.jsp.production.Message_jsp._jspService(Message_jsp.java:214)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:444)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:386)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:330)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)

这是我的配置文件:

prop.setProperty("hibernate.connection.url",  "jdbc:mysql://"+ip+":3306/database?autoReconnect=true");
prop.setProperty("hibernate.connection.username", "user");
prop.setProperty("hibernate.connection.password", "pass");
prop.setProperty("dialect", "org.hibernate.dialect.MySQLDialect");
prop.setProperty("hibernate.c3p0.min_size", "3");
prop.setProperty("hibernate.c3p0.max_size", "100");
prop.setProperty("hibernate.c3p0.timeout", "120");
prop.setProperty("hibernate.c3p0.max_statements", "1000");
prop.setProperty("hibernate.c3p0.idle_test_period", "100");
prop.setProperty("hibernate.c3p0.validate", "true");
prop.setProperty("hibernate.c3p0.acquire_increment", "1");
prop.setProperty("hibernate.c3p0.preferredTestQuery", "select 1;");

1 个答案:

答案 0 :(得分:0)

添加此设置属性

prop.setProperty("hibernate.current_session_context_class", "thread");

增加时间

prop.setProperty("hibernate.c3p0.idle_test_period", "3000");

删除此属性

 prop.setProperty("hibernate.c3p0.acquire_increment", "1");
 prop.setProperty("hibernate.c3p0.preferredTestQuery", "select 1;");