I've encountered a similar problem using Proxool.
I've also debugged and located the problem:
The connections are exhausted in the following case:
You load entities within a transaction, and commit the transaction. If you try to access a uninitialized association, hibernate initializes lazy associations: a connection is requested and not freed anymore.
Therefore my solution was to free them manually:
in the getter of one-to-one associations put the following:
if (!((HibernateProxy) ref).getHibernateLazyInitializer().getSession()
.getJDBCContext().isTransactionInProgress()) {
((HibernateProxy) ref).getHibernateLazyInitializer().getSession()
.getJDBCContext().afterNontransactionalQuery(true);
}
(while ref is the proxy).
on one-to-many:
if (!persistentSet.getCurrentSession().getJDBCContext().isTransactionInProgress()) {
persistentSet.getCurrentSession().getJDBCContext().afterNontransactionalQuery(true);
}
(while persistenSet is the Hibernate Proxy (PersistentSet)), if you use another collection type, use it instead.
The core is if you are not in a transaction, hibernate forgets to free the connection used for lazy loading, afterNonTransactionalQuery does this.
Hope this helps!
|