我正在使用spring 3.05 + mysql,程序运行后,我从日志中发现了很多异常:
books.log.6- 09:24:45 Closing JPA EntityManager -org.springframework.orm.jpa.EntityManagerFactoryUtils
books.log.6- 09:24:45 about to close PreparedStatement (open PreparedStatements: 1, globally: 1) -org.hibernate.jdbc.AbstractBatcher
books.log.6- 09:24:45 aggressively releasing JDBC connection -org.hibernate.jdbc.ConnectionManager
books.log.6- 09:24:45 releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)] -org.hibernate.jdbc.ConnectionManager
books.log.6- 09:24:45 Cannot release connection [???] -org.hibernate.util.JDBCExceptionReporter
books.log.6: java.sql.SQLException: Already closed.
books.log.6- at org.apache.commons.dbcp.PoolableConnection.close(PoolableConnection.java:114)
books.log.6- at org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.close(PoolingDataSource.java:191)
books.log.6- at org.hibernate.connection.DatasourceConnectionProvider.closeConnection(DatasourceConnectionProvider.java:97)
books.log.6- at org.hibernate.jdbc.ConnectionManager.closeConnection(ConnectionManager.java:474)
books.log.6- at org.hibernate.jdbc.ConnectionManager.aggressiveRelease(ConnectionManager.java:429)
books.log.6- at org.hibernate.jdbc.ConnectionManager.afterStatement(ConnectionManager.java:304)
books.log.6- at org.hibernate.jdbc.AbstractBatcher.closePreparedStatement(AbstractBatcher.java:572)
books.log.6- at org.hibernate.jdbc.AbstractBatcher.closeStatement(AbstractBatcher.java:291)
books.log.6- at org.hibernate.jdbc.AbstractBatcher.closeQueryStatement(AbstractBatcher.java:307)
books.log.6- at org.hibernate.jdbc.AbstractBatcher.closeQueryStatement(AbstractBatcher.java:234)
books.log.6- at org.hibernate.loader.Loader.getResultSet(Loader.java:1967)
books.log.6- at org.hibernate.loader.Loader.doQuery(Loader.java:802)
books.log.6- at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274)
books.log.6- at org.hibernate.loader.Loader.doList(Loader.java:2533)
books.log.6- at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276)
books.log.6- at org.hibernate.loader.Loader.list(Loader.java:2271)
books.log.6- at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:452)
books.log.6- at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:363)
books.log.6- at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
books.log.6- at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1268)
books.log.6- at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
books.log.6- at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:246)
books.log.6- at com.tekelec.books.domain.BookInfo.findAllBooks_aroundBody4(BookInfo.java:238)
books.log.6- at com.tekelec.books.domain.BookInfo.findAllBooks(BookInfo.java:1)
books.log.6- at com.tekelec.books.web.BooksController.getBooks(BooksController.java:37)
books.log.6- at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
books.log.6- at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
books.log.6- at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
books.log.6- at java.lang.reflect.Method.invoke(Method.java:616)
books.log.6- at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:212)
我知道这是由 Mysql 引起的——经过数小时的空闲后,它最初关闭了连接,而从 dbcp 端看起来它仍然活着。由于 Mysql 服务于多个数据库实例,所以我需要从我的应用程序代码方面进行更改。
我的问题是,例外真的重要吗?JPA 会在失败后重试连接吗?
谢谢!