gpt4 book ai didi

java - Hibernate JDBC 连接在一分钟后断开

转载 作者:行者123 更新时间:2023-11-29 17:17:57 27 4
gpt4 key购买 nike

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

这是错误:

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

关于java - Hibernate JDBC 连接在一分钟后断开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51442825/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com