1

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

ありがとう!

4

1 に答える 1

0

に検証クエリ ( select 1) を追加する必要がありますDataSource

<Resource name="jdbc/cfmediaarchive" type="javax.sql.DataSource"
    driverClassName="com.mysql.jdbc.Driver"
    url="jdbc:mysql://localhost:3306/mydb?useUnicode=true&amp;characterEncoding=utf8"

    auth="Container" username="username" password="password"

    maxIdle="3" maxActive="15" maxWait="10000" logAbandoned="true" removeAbandoned="true" removeAbandonedTimeout="60" 

    validationQuery="select 1" />

春の設定:

spring.xml

   <bean id="dataSource"
    class="org.apache.commons.dbcp.BasicDataSource"
    destroy-method="close">
    <property name="driverClassName" value="${driverClassName}" />
    <property name="url" value="${url}" />
    <property name="username" value="${username}" />
    <property name="password" value="${password}" />
    <property name="validationQuery" value="select 1"/>
</bean>

  <bean
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
    id="entityManagerFactory">
    <property name="persistenceUnitName" value="persistenceUnit" />
    <property name="dataSource" ref="dataSource" />
    <!-- this is important to connect JPA and JdbcTemplate transaction control -->
    <property name="jpaVendorAdapter">
        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
            <property name="showSql" value="false" />
        </bean>
    </property>
</bean>

persistence.xml

<persistence-unit name="persistenceUnit" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <properties>
        <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
        <property name="hibernate.hbm2ddl.auto" value="validate" />
        <property name="hibernate.connection.charSet" value="UTF-8" />
        <property name="hibernate.show_sql" value="false" />

    </properties>
</persistence-unit>
于 2012-07-02T04:56:19.693 に答える