【问题标题】:Setting c3p0 configuration for long running query为长时间运行的查询设置 c3p0 配置
【发布时间】:2014-04-28 02:37:14
【问题描述】:

我使用的是 Hibernate 3.3.1 和 jtds 1.2.2 作为 JDBC 驱动程序和 c3p0 版本 0.9.1.2 用于连接池以连接 SQL Server。

我的查询运行大约需要 12 秒。 当我运行查询时,我得到以下异常

ERROR [main] (JDBCExceptionReporter.java:101) - 无效状态,Connection 对象已关闭。 org.hibernate.exception.GenericJDBCException:无法检查 JDBC 自动提交模式 在 org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:126) 在 org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:114) 在 org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66) 在 org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:52) 在 org.hibernate.jdbc.JDBCContext.afterNontransactionalQuery(JDBCContext.java:275) 在 org.hibernate.impl.SessionImpl.afterOperation(SessionImpl.java:444) 在 org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1728) 在 org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:165) 在 org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:175)

如果我修改查询以返回一小组数据,我不会得到异常。 好像配置有问题。

在我的 hibernate.properties 文件中,我有以下配置值

hibernate.format_sql=true
hibernate.dialect=org.hibernate.dialect.SQLServerDialect
hibernate.optimistic-lock=true
hibernate.connection.autocommit=true
hibernate.show_sql=false
hibernate.generate_statistics=false
c3p0.acquire_increment=1
c3p0.idle_test_period=1000
c3p0.max_size=10     
c3p0.max_statements=0     
c3p0.min_size=5     
c3p0.timeout=800

您能否建议需要设置哪些参数才能运行长时间运行的查询?

谢谢

【问题讨论】:

    标签: java sql hibernate c3p0 jtds


    【解决方案1】:

    c3p0 不需要对长时间运行的查询进行特殊设置,尽管有一些设置(特别是 unreturnedConnectionTimeout)可能会干扰长时间运行的查询。

    我会确认未设置 unreturnedConnectionTimeout。 (有很多地方可能会在 hibernate.properties 文件之外设置 c3p0 配置。) c3p0 转储其配置以在池初始化时登录 INFO。查找 unreturnedConnectionTimeout 的值。它应该是 0。

    如果它为 0,则 c3p0 级别的任何内容都不会干扰您的长时间查询。

    【讨论】:

      猜你喜欢
      • 2020-11-20
      • 2010-12-03
      • 1970-01-01
      • 1970-01-01
      • 2011-06-04
      • 1970-01-01
      • 1970-01-01
      • 2018-04-20
      • 1970-01-01
      相关资源
      最近更新 更多