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

这是错误:

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)

And this is my configuration file:

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;");

最佳答案

添加此设置属性

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;");

08-26 18:35