Keep getting org.hibernate.exception.JDBCConnectionException: could not execute query

前端 未结 2 489
醉梦人生
醉梦人生 2021-01-23 05:15

I\'ve got a J2EE application which uses JSP pages as front end and Struts2 as controller. I also use Hibernate to map my objects into a MySql DB. when I deploy the application o

2条回答
  •  既然无缘
    2021-01-23 05:37

    Hibernate uses a primitive connection pooling mechanism, which is not suitable for production purposes (it even says that in the log file!). You should always use a connection pooling mechanism, be it the one provided by your container, be it a mechanism bundled in your application (c3p0, for instance). The exception you are seeing is because MySQL closed an "old" connection which Hibernate is still using. You can try to add a JDBC URL option, like "autoReconnect", but that's really not a long-term solution.

    Ideally, you should configure your container to supply the connections to your application through JNDI. This is easily done with a "-ds.xml" file in JBoss or with a context.xml for Tomcat.

提交回复
热议问题