Note that there are some explanatory texts on larger screens.

plurals
  1. POHibernate cannot open connection
    primarykey
    data
    text
    <p>I'm having trouble with hibernate not able to open a connection. I have a DAO:</p> <pre><code>public class MyDao extends HibernateDaoSupport { DataSource dataSource; public void setDataSource(DataSource dataSource) { this.dataSource = dataSource; } public MyPOJO findByQuery(int hour) { Query query = this.getSession().createSQLQuery( "SELECT * FROM MyPOJO WHERE someDate &gt;= DATE_SUB(now(), INTERVAL ? HOUR)") .addEntity(MyPOJO.class); List&lt;MyPOJO&gt; results = query.setInteger(0, hours).list(); return results; } } </code></pre> <p>and then in a test case call findByQuery(1) 8 times, it works, but if I call a 9th time it fails with:</p> <pre><code>org.hibernate.exception.GenericJDBCException: Cannot open connection at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103) at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29) at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:426) at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:144) at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:139) at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1547) at org.hibernate.loader.Loader.doQuery(Loader.java:673) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236) at org.hibernate.loader.Loader.doList(Loader.java:2213) at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104) at org.hibernate.loader.Loader.list(Loader.java:2099) at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:289) at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1695) at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142) at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:152) Caused by: org.apache.commons.dbcp.SQLNestedException: Could not retrieve connection info from pool at org.apache.commons.dbcp.datasources.SharedPoolDataSource.getPooledConnectionAndInfo(SharedPoolDataSource.java:169) at org.apache.commons.dbcp.datasources.InstanceKeyDataSource.getConnection(InstanceKeyDataSource.java:631) at org.apache.commons.dbcp.datasources.InstanceKeyDataSource.getConnection(InstanceKeyDataSource.java:615) at org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider.getConnection(LocalDataSourceConnectionProvider.java:81) at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:423) ... 35 more Caused by: java.util.NoSuchElementException: Timeout waiting for idle object at org.apache.commons.pool.impl.GenericKeyedObjectPool.borrowObject(GenericKeyedObjectPool.java:827) at org.apache.commons.dbcp.datasources.SharedPoolDataSource.getPooledConnectionAndInfo(SharedPoolDataSource.java:165) ... 39 more </code></pre> <p>This is what my hibernate properties look like:</p> <pre><code>&lt;property name="hibernateProperties"&gt; &lt;props&gt; &lt;prop key="hibernate.dialect"&gt; org.hibernate.dialect.MySQL5Dialect &lt;/prop&gt; &lt;prop key="hibernate.current_session_context_class"&gt; thread &lt;/prop&gt; &lt;prop key="hibernate.format_sql"&gt;false&lt;/prop&gt; &lt;prop key="hibernate.show_sql"&gt;false&lt;/prop&gt; &lt;prop key="hibernate.use_sql_comments"&gt;false&lt;/prop&gt; &lt;prop key="hibernate.jdbc.use_get_generated_keys"&gt;true&lt;/prop&gt; &lt;prop key="hibernate.cache.use_second_level_cache"&gt;true&lt;/prop&gt; &lt;prop key="hibernate.cache.provider_class"&gt; org.hibernate.cache.EhCacheProvider &lt;/prop&gt; &lt;prop key="hibernate.connection.release_mode"&gt;auto&lt;/prop&gt; &lt;/props&gt; &lt;/property&gt; </code></pre> <p>If I change the release_mode to 'after_statement' (ala <a href="http://docs.jboss.org/hibernate/stable/core/reference/en/html_single/#transactions-connection-release" rel="nofollow noreferrer">http://docs.jboss.org/hibernate/stable/core/reference/en/html_single/#transactions-connection-release</a>) it will work, but I don't understand that and feel like that is just a band-aid for something bigger that I am doing wrong.</p> <p>I've also tried to flush and close the this.getSession() with no luck either. I can see the close() gets called AFTER all of the calls to findByQuery(1) have completed.</p> <p>This is on Hibernate 3.2.6, Spring 3.0 and MySQL 5.1. Let me know what more information I can provide.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload