Hi everyone
We have some problems with connection pooling.
We have built a server using Hibernate 2.1.2 (of course) and use SOAP technology with resin. Also we are using the following configuration in hibernate.properties:
hibernate.connection.provider_class = net.sf.hibernate.connection.DBCPConnectionProvider
hibernate.dbcp.validationQuery=Select 1
hibernate.dbcp.maxActive=10
hibernate.dbcp.maxIdle=5
hibernate.dbcp.maxWait=3000
hibernate.dbcp.whenExhaustedAction=1
hibernate.dbcp.ps.maxActive=50
hibernate.dbcp.ps.maxIdle=10
hibernate.dbcp.ps.maxWait=3000
hibernate.dbcp.ps.whenExhaustedAction=1
When I delete an object I get the following error:
09:25:21,400 ERROR HibernatePropertyGroupFactory:196 - ***ERROR: net.sf.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions
09:25:21,406 ERROR HibernatePropertyGroupFactory:206 - ***ERROR: net.sf.hibernate.HibernateException: Session already disconnected
The code I use looks typically like this:
Code:
public List find(String pHql) {
List list = null;
try {
session = factory.openSession();
list = session.find(pHql);
session.flush();
} catch (HibernateException e) {
if (session != null){
try {
session.flush();
session.disconnect();
} catch (HibernateException ex) {
throw new BackendException(
" Could not Close Connection.",
ex);
}
}
String err = " ***ERROR: executing '" + pHql + "'. ";
throw new BackendException(err, e);
} finally {
if (session != null){
try {
session.flush();
session.disconnect();
} catch (HibernateException e) {
throw new BackendException(
" Could not Close Connection.",
e);
}
}
}
if (list == null)
list = new java.util.ArrayList();
return (list);
}
My hypothesis is that the pooling causes the error. I know that I need to return the connection to the pool
not the session but I am uncertain how. After searching at google on the subject I think I know how. My interpretation of the information I found was that I disconnect the connection from the session with
session.disconnect() and then the connection is returned to the pool. So my first question is if
session.disconnect() returns the connection to the pool? My second question is how do I fix the errors that appear in my log (see above errors). The third question is do I need to close the session after I have disconnected it from the connection (the API say that I don't)?
Thanks in before half
Oscar Norlander