私は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は失敗後に接続を再試行しますか?
ありがとう!