为长时间运行的查询设置c3p0配置

时间:2014-03-20 22:42:08

标签: java sql hibernate c3p0 jtds

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

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

错误[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

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

谢谢

1 个答案:

答案 0 :(得分:0)

c3p0对长时间运行的查询不需要特殊设置,但有些设置(特别是unreturnedConnectionTimeout)可能会干扰长时间运行的查询(如果已设置)。

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

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