I work with Hibernate and Spring. I have written following code.
Code:
return (CurrentStatus) getHibernateTemplate().execute(new HibernateCallback()
{
@SuppressWarnings("unchecked")
public Object doInHibernate(Session session) throws HibernateException, SQLException
{
String queryString = "SELECT werk, format, status, intern, count(*) as anzahl from sstatus as status where werk = ? and richtung = ? and format = ? and status = ? and intern = ? and updated between ? and ? group by werk, format,status, intern order by werk, format, status, intern";
SQLQuery q = session.createSQLQuery(queryString);
q.setInteger(0, werk.getId());
q.setString(1, richtung);
q.setString(2, format);
q.setString(3, status);
q.setBoolean(4, intern);
q.setDate(5, anfang);
q.setDate(6, ende);
q.setCacheable(false);
q.addEntity("status", CurrentStatus.class);
List<CurrentStatus> o = q.list();
if (o.size() == 0) return new CurrentStatus(new CurrentStatusId(werk, format, status, richtung, intern), 0);
else
{
CurrentStatus cs = o.get(0);
return cs;
}
}
});
This function was executed many times to collect some statistic data in a matrix, but after a few times I become following Message.
Code:
2009-07-10 14:40:55,428 WARN (org.hibernate.util.JDBCExceptionReporter:77) - SQL Error: 0, SQLState: null
2009-07-10 14:40:55,428 ERROR (org.hibernate.util.JDBCExceptionReporter:78) - An attempt by a client to checkout a Connection has timed out.
2009-07-10 14:40:55,428 WARN (org.hibernate.util.JDBCExceptionReporter:77) - SQL Error: 0, SQLState: null
2009-07-10 14:40:55,428 ERROR (org.hibernate.util.JDBCExceptionReporter:78) - An attempt by a client to checkout a Connection has timed out.
10.07.2009 14:40:55 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [org/springframework/jdbc/support/sql-error-codes.xml]
10.07.2009 14:40:55 org.springframework.jdbc.support.SQLErrorCodesFactory <init>
INFO: SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL, Sybase]
10.07.2009 14:41:05 org.springframework.jdbc.support.SQLErrorCodesFactory getErrorCodes
WARNUNG: Error while extracting database product name - falling back to empty error codes
org.springframework.jdbc.support.MetaDataAccessException: Could not get Connection for extracting meta data; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: An attempt by a client to checkout a Connection has timed out.
at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:198)
at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:225)
at org.springframework.jdbc.support.SQLErrorCodesFactory.getErrorCodes(SQLErrorCodesFactory.java:216)
at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.setDataSource(SQLErrorCodeSQLExceptionTranslator.java:147)
.
.
.
.
Caused by: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: An attempt by a client to checkout a Connection has timed out.
at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:82)
at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:185)
... 87 more
Caused by: java.sql.SQLException: An attempt by a client to checkout a Connection has timed out.
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:106)
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:65)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:527)
at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:128)
at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:113)
at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:79)
... 88 more
Caused by: com.mchange.v2.resourcepool.TimeoutException: A client timed out while waiting to acquire a resource from com.mchange.v2.resourcepool.BasicResourcePool@86b376 -- timeout at awaitAvailable()
at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1317)
at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:557)
at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:477)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:525)
each select runs only arround 10ms why I become this timeout?
my configuration is:
Code:
<property name="checkoutTimeout" value="5000" />
<property name="initialPoolSize" value="5" />
<property name="minPoolSize" value="5" />
<property name="maxPoolSize" value="40" />
<property name="maxIdleTime" value="18000" />
<property name="acquireIncrement" value="5" />
<property name="maxIdleTimeExcessConnections" value="1800" />
Does anyone have a tip why hibernate become an error? In the Postgres Monitor I see only one Session is used all other are idle. I try different Pool sizes but the Error is still the same.